projects
/
perl.git
/ commitdiff
free
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
(parent:
a121486
)
[perl #114498] Document (0)[1,2] better
author
Aristotle Pagaltzis <pagaltzis@gmx.de>
Fri, 31 Aug 2012 15:45:37 +0000 (08:45 -0700)
committer
Father Chrysostomos <sprout@cpan.org>
Fri, 31 Aug 2012 15:48:03 +0000 (08:48 -0700)
pod/perldata.pod
patch
|
blob
|
blame
|
history
diff --git
a/pod/perldata.pod
b/pod/perldata.pod
index
3a4776c
..
9bff98f
100644
(file)
--- a/
pod/perldata.pod
+++ b/
pod/perldata.pod
@@
-777,13
+777,18
@@
A slice of an empty list is still an empty list. Thus:
@a = ()[1,0]; # @a has no elements
@b = (@a)[0,1]; # @b has no elements
- @c = (0,1)[2,3]; # @c has no elements
But:
@a = (1)[1,0]; # @a has two elements
@b = (1,undef)[1,0,2]; # @b has three elements
+More generally, a slice yields the empty list if it indexes only
+beyond the end of a list:
+
+ @a = (1)[ 1,2]; # @a has no elements
+ @b = (1)[0,1,2]; # @b has three elements
+
This makes it easy to write loops that terminate when a null list
is returned: