Negative Array Subscripts
To get the last element in a list or array, use $array[-1] instead of $array[$#array]
The former works on both lists and arrays, but the latter does not
Remember that substr, index, rindex, and splice also accept negative subscripts to count back from the end
splice(@array, -2); # pop twice
Remember substr is lvaluable:
substr($s, -10) =~ s/ /./g;
< Changing en passant
Embrace Hashes >
Table of Contents
|
Page 11
YAPC 19101
, June 2001
Perl Idioms
Nathan Torkington