-
Notifications
You must be signed in to change notification settings - Fork 561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implicit split to @_ considered counterintuitive #335
Comments
From @vlbrownWhen I run this code: $record = 'a b c d e f g'; $x = split(/\s+/, $record); print $x, "\n"; (under Perl 5.005_02) I get: Use of implicit split to @_ is deprecated at foo.pl line 5. What implicit split to @_? Sayeth the Camel: In scalar context, split returns the count of substrings Sayeth perlfunc (on 5.005_03) under 'split': "If not in list context, returns the number of fields found and splits Note the "returns the number of fields found *and* splits into @_" bit. The use of implicit split to @_ is deprecated? TAKE IT OUT. It should Perl Info
|
From [Unknown Contact. See original ticket]
What do you think of making things scheduled like this become I'll support giving the axe to the implicit split if we --tom |
From [Unknown Contact. See original ticket]In message <v04210108b3cd04005beb@[207.135.77.148]>, You ask this and then go on to quote the docs. I find that puzzling. : Note the "returns the number of fields found *and* splits into @_" bit. This is to support old code. Did you use version 4 or earlier? : The use of implicit split to @_ is deprecated? TAKE IT OUT. We don't like to snatch the rug from beneath people without bulletproof : It should not be there. It's deprecated. That means it's likely to be on the way out. Larry : This is scalar context, not sorta scalar and sorta list and It's documented behavior that has a long history. : Don't tell me that "in scalar context split returns a number" and then Don't read the docs and you won't have to learn anything you don't want : It should work or not but not give a warning. Try assigning to $* when you get a chance. You can disable warnings, : That's dumb. You misspelled "I'm". Greg |
From @tamiasOn Tue, Aug 03, 1999 at 01:39:52PM -0700, Vicki Brown wrote:
Features must not be removed from Perl without first going through a Ronald |
From [Unknown Contact. See original ticket]
Not as bad as breaking something. --tom |
From [Unknown Contact. See original ticket]Tom Christiansen writes:
Mandatory warnings suck. Have a deprecated warning set for the Nat |
From @vlbrownAt 16:39 -0600 8/3/99, Nathan Torkington wrote:
or use warnings 'of extreme stupidity checking' As it stands right now, my choices are either to turn off -w (no :) By forcing me to get this warning,the simple use of split in scalar I recognize the desire not to break code... although sometimes one |
From [Unknown Contact. See original ticket]Tom Christiansen writes:
These big breakages will only happen at a major version change, Larry Nat |
From [Unknown Contact. See original ticket]
When Larry effectively changed the precedences in perl4 to perl5, this % perl -ce 'open FILE || die' This is just one step away from complete compilation failure: % perl -ce 'print "fred@home"' I believe that anything that's getting a -w deprecated warning now in --tom |
From [Unknown Contact. See original ticket]
Or to be more imaginative: $count = do { my @tmp = split /:/, $line }; --tom |
From [Unknown Contact. See original ticket]Tom Christiansen[SMTP:tchrist@jhereg.perl.com] wrote:
...or an old standby: $count=@{[split /:/,$line]}; TMTOWTDI, Jim Williams |
From @perhunter
WJP> Tom Christiansen[SMTP:tchrist@jhereg.perl.com] wrote: WJP> ...or an old standby: WJP> $count=@{[split /:/,$line]}; since it is only a single char, why not just use tr/// to count the : uri -- |
From [Unknown Contact. See original ticket]On Tue, Aug 03, 1999 at 08:08:56PM -0500, "Williams, James P" wrote:
$count = length$line&&1+$line=~tr/://; :-) mark P.S. Errr ... it's late at night ... and the evil perl gremlin got to me ... $count = length($line) && 1 + $line =~ tr/://; It only works if the separator is one literal character, and the use Benchmark; $line = "1:field2:this_is_field3:4:field5:this_is_field6"; timethese(500000, { Output: Benchmark: timing 500000 iterations of JamesW, MarkM, TomC... I don't even know why I'm still at work... sheesh... But I did finally come up with a use for short circuiting &&... :-) -- One ring to rule them all, one ring to find them, one ring to bring them all http://mark.mielke.cc/ |
From @pmqsFrom: Nathan Torkington [mailto:gnat@frii.com]
Err, there already is a "deprecated" lexical warning category. Paul |
From [Unknown Contact. See original ticket]On Tue, 03 Aug 1999 at 13:39:52 -0700, Vicki Brown wrote:
The Camel evidently tells not the full truth. Ask for your money back.
Not really dumb; it's history. Perl runs many scripts (it runs, There isn't, I grant you, any handy way of counting RE matches in a Ian |
From [Unknown Contact. See original ticket]Greg Bacon wrote:
The bit from "Sayeth perlfunc" up to "...split into @_" bit" (three Cheers, |
From [Unknown Contact. See original ticket]Uri Guttman wrote:
Because the thread that started the posting used split(/\s+/, $record). Cheers, |
From [Unknown Contact. See original ticket]On Tue, Aug 03, 1999 at 04:41:22PM -0600, Tom Christiansen wrote:
Mandatory warnings sometimes break things. We have projects that Peace, |
From [Unknown Contact. See original ticket]On Tue, 03 Aug 1999 at 16:43:12 -0600, Nathan Torkington wrote:
The reality is that people run scripts they don't fully (or at all) If there is to be a continuity between what we have now and what somes [Of course, 'foolproof' underestimates the sheer tenacity of fools. I had Ian |
From [Unknown Contact. See original ticket]
>> As it stands right now, my choices are either to turn off -w Tom> Or to be more imaginative: Tom> $count = do { my @tmp = split /:/, $line }; Isn't $cnt = () = split /:/, $line; enough? -- |
From [Unknown Contact. See original ticket]On 04 Aug 1999 15:21:53 -0700, Stephen Zander wrote (in part): Stephen> Isn't Stephen> $cnt = () = split /:/, $line; Stephen> enough? Only in newer perls. 4.036 requires $cnt = ($tmp) = split(/:/,$line); /spider |
From [Unknown Contact. See original ticket]
Sure. But it *is* a neologism. :-) -tom |
From @mjdominus
The right-hand side of the $cnt= assignment is a list assignment while (($k, $v) = each %h) { ... } or while (($x, $y, $z) = split ...) { ... } work. The former terminates the loop when each() returns the empty When the result of split() is assigned to a list, the third argument ($x, $y) = split P, S; is equivalent to: ($x, $y) = split P, S, 3; In your example, you have () = split /:/, $a; This is equivalent to () = split /:/, $a, 1; Therefore, the number of items available for assignment is 1. |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 10:47:34AM -0600, "Tom Christiansen" wrote:
$ perl -e ' Ok then. Colour me blinded by my experimentation? $ perl -v This is perl, version 5.005_03 built for sun4-solaris mark -- One ring to rule them all, one ring to find them, one ring to bring them all http://mark.mielke.cc/ |
From @RandalSchwartz
Mark> I thought the rule for: Mark> scalar = list Mark> Was that the scalar recieved the last scalar in the list??? there is no rule for: scalar = list because it can never happen. The right-hand side is evaluated in a Get the idea? THERE CANNOT BE A LIST IN A SCALAR CONTEXT. :) -- |
From [Unknown Contact. See original ticket]On Wed, 4 Aug 1999, Spider Boardman wrote:
Broken in _60 then? perl -we '$line="q:a:d:e"; $cnt = () = split /:/, $line; print $cnt' And surely $cnt = ($tmp) = split(/:/,$line); should always set $cnt = 2 ? John. |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 09:22:29AM -0600, "Tom Christiansen" wrote:
Umm... is anybody sure this works? I thought the rule for: scalar = list Was that the scalar recieved the last scalar in the list??? mark -- One ring to rule them all, one ring to find them, one ring to bring them all http://mark.mielke.cc/ |
From [Unknown Contact. See original ticket]
Please RTFM. That's not what's going on here. --tom |
From @RandalSchwartz
Mark> On Wed, Aug 04, 1999 at 09:54:20AM -0700, "Randal L. Schwartz" wrote:
Mark> Of if there isn't a method of coercing a list into a scalar... but their no, there's no "list" in a scalar context. What are you calling a list? Mark> Seem to me that "evaluating in scalar context" "coercing to a scalar" That's because you're erroneously making them the same. There are no Perl constructs that even return a list in a scalar context. Mark> We're playing word games here??? No, *you* are. -- |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 09:54:20AM -0700, "Randal L. Schwartz" wrote:
Of if there isn't a method of coercing a list into a scalar... but their Seem to me that "evaluating in scalar context" "coercing to a scalar" We're playing word games here??? I just want to know why people are saying: $cnt = () = split /:/, $line; Works ... when I can't get it to work? mark -- One ring to rule them all, one ring to find them, one ring to bring them all http://mark.mielke.cc/ |
From [Unknown Contact. See original ticket]Would some kind sole explain to me why this gives any result at all? perl -wle '$cnt = () = (1,2,3); print $cnt' I would have expected this to be a fatal error. Isn't () rvalued? <chaim>
GB> In message <19990804125927.C24774@bmers31f.ca.nortel.com>, GB> We discussed this on clpmisc recently. Incant GB> $cnt = () = split /:/, $line, -1; GB> Bug? -- |
From [Unknown Contact. See original ticket]paul.marquess@bt.com writes:
We need another category: really-deprecated with warnings being *on* Could you do it before Sarathy is back? Ilya |
From @tamiasOn Wed, Aug 04, 1999 at 03:31:45PM -0400, Chaim Frenkel wrote:
Not sure why it would be a fatal error. It's a common idiom in Perl5. It's just like this: ($foo) = (1,2,3); except instead of being 2 lvalues short, it's 3 lvalues short. The extra A list assignment in scalar context returns the number of values on the Ronald |
From [Unknown Contact. See original ticket]
This is bad? |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 05:45:38PM -0400, Joshua N Pritikin wrote:
perl5.005_60->./perl -le '$x = split'
How would *you* do it? Ilya |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 04:57:34PM -0400, ilya@math.ohio-state.edu wrote:
Are you saying that the "deprecated" lexical warning category is *not* (1) deprecated warning off by default -- |
From [Unknown Contact. See original ticket]On Wed, Aug 04, 1999 at 03:55:26PM -0600, tchrist@jhereg.perl.com wrote:
Perhaps it is a good idea. It'll allow fewer objections from the -- |
From @gbarrOn Wed, Aug 04, 1999 at 01:44:06PM -0400, Mark Mielke wrote:
Yes it does, and it's even documented too
No it is not. In $cnt = () = split(/:/,$line) $cnt has no more effect on the context that split is called in than $cnt = @a = split(/:/,$line); although this would give a different result to the first statement. This is because this is two expressions, not one. First () = split(/:/,$line) is evaluated, this calls split in a list context. split is documented The secons expression is the scalar value of a list assignment. This So as you can see, I hope, this is not a bug. -- |
From @pmqsFrom: Ilya Zakharevich [mailto:ilya@math.ohio-state.edu]
Correct. The current set of warnings in the 'deprecated' class are all
The -w flag doesn't trigger lexical warnings. use warning 'deprecated'; % perl5.00560 /tmp/lex
Isn't (1) all that has happened to date? Have we actually done (2) and/or Paul |
From @pmqsFrom: Ilya Zakharevich [mailto:ilya@math.ohio-state.edu]
The categories currently defined for lexical warnings are classed as
:-) When does he get back? Paul |
From [Unknown Contact. See original ticket]On Thu, Aug 05, 1999 at 09:12:09AM +0100, paul.marquess@bt.com wrote:
We did not do it because it was not possible to do. And we will not Ilya |
From [Unknown Contact. See original ticket]That's not an obvious result, and what about the following? $cnt = ($a, $b, $c) = () = (1,2,3); Why does the count get through on () = (1,2,3) case but not in <chaim>
RJK> On Wed, Aug 04, 1999 at 03:31:45PM -0400, Chaim Frenkel wrote:
RJK> Not sure why it would be a fatal error. It's a common idiom in Perl5. RJK> It's just like this: RJK> ($foo) = (1,2,3); RJK> except instead of being 2 lvalues short, it's 3 lvalues short. The extra RJK> A list assignment in scalar context returns the number of values on the -- |
From @tamiasOn Thu, Aug 05, 1999 at 10:39:00AM -0400, Chaim Frenkel wrote:
In a scalar context, list assignment returns the number of elements on the Working from right to left: () = (1,2,3) assigns the list (1,2,3) to nothing. ($a, $b, $c) = () = (1,2,3) assigns the empty list to ($a, $b, $c). $cnt = ($a, $b, $c) = () = (1,2,3) assigns 0 to $cnt. Ronald |
From [Unknown Contact. See original ticket]Chaim Frenkel writes:
chaim@localhost> grep -i 'list assignment' pod/* pod/perldata.pod:List assignment in scalar context returns the number of elements chaim@localhost> man perldata Nat |
From @tamiasOn Thu, Aug 05, 1999 at 04:31:10PM -0400, Chaim Frenkel wrote:
perldata: Array assignment in a scalar context returns the number of $x = (($foo,$bar) = (3,2,1)); # set $x to 3, not 2 Note that this should say 'list assignment', not 'array assignment'. The I don't know if there is explicit mention of list assignment in list Ronald |
From [Unknown Contact. See original ticket]
RJK> In a scalar context, list assignment returns the number of elements on the Please point me at the documentation for this. <chaim> |
From [Unknown Contact. See original ticket]On Thu, Aug 05, 1999 at 04:31:10PM -0400, "Chaim Frenkel" wrote:
I can't seem to find it. (Doesn't mean it doesn't exist) ($rest) = ($first, $second) = split(/\s+/, "abc def ghi jkl"); ($rest) = ($first, $second) = ("abc", "def", "ghi", "jkl"); Outputs: abc, def, abc And: $scalar = ($first, $second) = ("abc", "def", "ghi", "jkl"); Outputs: 4D So... it appears... in contradiction to what Randall believes... Apparent rules: # FORM: scalar = value1, value2, ...; # FORM: scalar = rvalue_list; # FORM: scalar = lvalue_list = rvalue_list # FORM: scalar = lvalue_list = split(pat, string) This all seems highly magical... anyways... mark -- One ring to rule them all, one ring to find them, one ring to bring them all http://mark.mielke.cc/ |
From @tamiasOn Thu, Aug 05, 1999 at 05:01:30PM -0400, Mark Mielke wrote:
Your input terminator is showing. :)
s/Randall/Randal/; Yes, there is such a thing as a list, but not in a scalar context.
$a will be 1, not 3, because = has higher precedence than ,. The other
In a scalar context, the comma operator evaluates its first argument, then This is what is meant by "there is no such thing as a list in a scalar
The scalar gets assigned the length of the rvalue_list, just as in the Ronald |
Hello from 2023!!! |
😂😂😂😂😂😂😂😂😂😂😂😂 |
Migrated from rt.perl.org#1164 (status was 'resolved')
Searchable as RT1164$
The text was updated successfully, but these errors were encountered: