From f51152efb95ba4281387bc22b0734fb4c3ed3ad1 Mon Sep 17 00:00:00 2001 From: Aristotle Pagaltzis Date: Fri, 31 Aug 2012 08:45:37 -0700 Subject: [PATCH] [perl #114498] Document (0)[1,2] better --- pod/perldata.pod | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pod/perldata.pod b/pod/perldata.pod index 3a4776c..9bff98f 100644 --- 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: -- 2.7.4