summaryrefslogtreecommitdiff
path: root/pod/perldata.pod
diff options
context:
space:
mode:
authorMoritz Lenz <moritz@faui2k3.org>2010-10-21 11:45:20 +0200
committerDavid Golden <dagolden@cpan.org>2010-10-21 06:54:40 -0400
commitad1de9c6347c3e74fab7b1675e069dfc8b67d44c (patch)
tree2da42a6e23552d9f8702d7f87b67dc89ce63c79f /pod/perldata.pod
parenta4051d2977a92b90787a41f76f3ae82ad6401d66 (diff)
downloadperl-ad1de9c6347c3e74fab7b1675e069dfc8b67d44c.tar.gz
document slices in scalar context
Diffstat (limited to 'pod/perldata.pod')
-rw-r--r--pod/perldata.pod7
1 files changed, 7 insertions, 0 deletions
diff --git a/pod/perldata.pod b/pod/perldata.pod
index bc564e650d..4f08d24490 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.