in reply to Perl Idioms Explained - my $count = () = /.../g
a list assignment in scalar context returns the number of elements on the right-hand side of the list assignmentI don't agree with that. An array assignment does this. A list assignment returns the last element. To wit:
@A = (1,3,5); $scalar_array = @A; $scalar_list = (1,3,5); $scalar_weird = (1..5); print "SA: ", $scalar_array, $/; print "SL: ", $scalar_list, $/; print "SW: ", $scalar_weird, $/; =for shell metaperl@pool-71-109-151-76:~/tmp$ perl a.pl SA: 3 SL: 5 SW: =cut
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Perl Idioms Explained - my $count = () = /.../g
by japhy (Canon) on Feb 05, 2006 at 21:23 UTC | |
Re^2: Perl Idioms Explained - my $count = () = /.../g
by MrCricket (Sexton) on Dec 17, 2015 at 15:18 UTC |
In Section
Meditations