| [reply] [d/l] [select] |
See List value constructors in perldata
perldata! Thanks!
but if you're assigning from an array or list, it's usually more sane to use some kind of slice rather than fooling around with undef.
Why? To make a slice in this case you'd need to know in advance how many matches there will be, or first store the output in an array and then slice away the first element. It's doable and understandable, but I don't see how skipping a value with undef is less sane.
| [reply] |
Why? To make a slice in this case ...
The particular case I had in mind was the
(undef, my %section) = split /(SECTION \d+)/, $text;
statement dealing with return values from the split built-in function, and I agree that in this kind of case, assignment to undef is reasonable and IMHO preferable.
However, I was trying to make the additional point that this kind of assignment works with any array or list assignment, e.g.,
c:\@Work\Perl\monks>perl -wMstrict -le
"my @ra = qw(zero one two three four five);
;;
my (undef, undef, $x, $y) = @ra;
print qq{'$x' '$y'};
"
'two' 'three'
and that in this sort of case it's (usually) better to use some kind of slice, e.g.,
my ($x, $y) = @ra[ 2, 3 ];
Give a man a fish: <%-{-{-{-<
| [reply] [d/l] [select] |