zeltus has asked for the wisdom of the Perl Monks concerning the following question:
I think my question is to do with array slices... but of course, I may be wrong!
my @tarray = qw(one two three four five); my ($v2) = @tarray; my $v3 = (@tarray)[0];
Now, I am used to extracting slices using
my $v3 = (@tarray)[0];
in this case, extract the first element from @tarray and "give" it to $v3...but upon examining some legacy code, I came across...
my ($v2) = @tarray;
...which does the same thing. But I can't work out why it works. Can someone please explain? Is it classifiable as a form or array slicing? I prefer my way for clarity, but are there any pros and cons for either method?
Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: array slice?
by Athanasius (Archbishop) on Jan 31, 2014 at 15:32 UTC | |
by zeltus (Beadle) on Feb 03, 2014 at 12:29 UTC | |
|
Re: array slice?
by zeltus (Beadle) on Jan 31, 2014 at 14:33 UTC | |
|
Re: array slice?
by kcott (Archbishop) on Feb 01, 2014 at 01:13 UTC |