File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,21 @@ Note that this is I<also> the behaviour in Perl 5:
186
186
perl -E "say scalar(my @array = [])" #=> 1
187
187
perl -E "say scalar(my @array = ())" #=> 0
188
188
189
+ = head2 Referencing the last element of an array
190
+
191
+ In Perl 5 one could reference the last element of an array by asking for the
192
+ "-1th" element of the array, e.g.:
193
+
194
+ my @array = qw{victor alice bob charlie eve};
195
+ say @array[-1]; #=> eve
196
+
197
+ In Perl 6 it is not possible to use negative subscripts, however the same is
198
+ achieved by actually using a function, namely C < *-1 > . Thus accessing the
199
+ last element of an array becomes:
200
+
201
+ my @array = qw{victor alice bob charlie eve};
202
+ say @array[*-1]; #=> eve
203
+
189
204
= end pod
190
205
191
206
# vim: expandtab shiftwidth=4 ft=perl6
You can’t perform that action at this time.
0 commit comments