in reply to Re^4: Regex to array
in thread Regex to array

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^6: Regex to array
by Eily (Monsignor) on Jan 10, 2018 at 09:20 UTC

    Oh alright then, it's mostly a style issue right? I agree that when you can use a slice on an array it is better (at least because it's more common so less confusing). I personally don't like slices on lists (ie: aritrary expressions in parentheses); most of the time I just use a temp array that I can slice from but otherwise I'd rather go with the undef version.