In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/ad1de9c6347c3e74fab7b1675e069dfc8b67d44c?hp=a4051d2977a92b90787a41f76f3ae82ad6401d66>
- Log ----------------------------------------------------------------- commit ad1de9c6347c3e74fab7b1675e069dfc8b67d44c Author: Moritz Lenz <[email protected]> Date: Thu Oct 21 11:45:20 2010 +0200 document slices in scalar context ----------------------------------------------------------------------- Summary of changes: pod/perldata.pod | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/pod/perldata.pod b/pod/perldata.pod index bc564e6..4f08d24 100644 --- a/pod/perldata.pod +++ b/pod/perldata.pod @@ -761,6 +761,13 @@ is the number of elements on the right-hand side of the assignment. The null list contains no elements, so when the password file is exhausted, the result is 0, not 2. +Slices in scalar context return the last item of the slice. + + @a = qw/first second third/; + %h = (first => 'A', second => 'B'); + $t = @a[0, 1]; # $t is now 'second' + $u = @h{'first', 'second'}; # $u is now 'second' + If you're confused about why you use an '@' there on a hash slice instead of a '%', think of it like this. The type of bracket (square or curly) governs whether it's an array or a hash being looked at. -- Perl5 Master Repository
