Assigning to C<$#days> actually changes the length of the array.
Shortening an array this way destroys intervening values. Lengthening
an array that was previously shortened does not recover values
-that were in those elements. (It used to do so in Perl 4, but we
-had to break this to make sure destructors were called when expected.)
+that were in those elements.
X<$#> X<array, length>
You can also gain some minuscule measure of efficiency by pre-extending
$0 and the $s variables in the (presumably) non-existent package
C<who>.
-In fact, an identifier within such curlies is forced to be a string,
-as is any simple identifier within a hash subscript. Neither need
+In fact, a simple identifier within such curlies is forced to be
+a string, and likewise within a hash subscript. Neither need
quoting. Our earlier example, C<$days{'Feb'}> can be written as
C<$days{Feb}> and the quotes will be assumed automatically. But
anything more complicated in the subscript will be interpreted as an
@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: