Grimnebulin has asked for the wisdom of the Perl Monks concerning the following question:
This perlop man page states that "...a list assignment in scalar context returns the number of elements produced by the expression on the right hand side of the assignment." So, I would have expected each of the previous commands to print "5". What the heck is going on?$ perl -le '$n = () = split /,/, "1,2,3,4,5"; print $n' 1 $ perl -le '$n = ($a) = split /,/, "1,2,3,4,5"; print $n' 2 $ perl -le '$n = ($a, $b) = split /,/, "1,2,3,4,5"; print $n' 3 $ perl -le '$n = ($a, $b, $c) = split /,/, "1,2,3,4,5"; print $n' 4
This is on perl 5.8.4.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
•Re: List assignment in scalar context
by merlyn (Sage) on Jan 10, 2005 at 18:45 UTC | |
by Grimnebulin (Initiate) on Jan 10, 2005 at 19:05 UTC | |
by tye (Sage) on Jan 10, 2005 at 20:00 UTC | |
by demerphq (Chancellor) on Jan 10, 2005 at 19:32 UTC | |
by dragonchild (Archbishop) on Jan 10, 2005 at 18:50 UTC | |
by !1 (Hermit) on Jan 10, 2005 at 19:21 UTC | |
by dragonchild (Archbishop) on Jan 10, 2005 at 19:25 UTC | |
by !1 (Hermit) on Jan 10, 2005 at 19:32 UTC | |
by jonadab (Parson) on Jan 11, 2005 at 00:15 UTC | |
by Aristotle (Chancellor) on Jan 10, 2005 at 22:35 UTC |