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
mean that it comes out in that order. See L<perlfunc/sort> for examples
of how to arrange for an output ordering.
+If a key appears more than once in the initializer list of a hash, the last
+occurrence wins:
+
+ %circle = (
+ center => [5, 10],
+ center => [27, 9],
+ radius => 100,
+ color => [0xDF, 0xFF, 0x00],
+ radius => 54,
+ );
+
+ # same as
+ %circle = (
+ center => [27, 9],
+ color => [0xDF, 0xFF, 0x00],
+ radius => 54,
+ );
+
+This can be used to provide overridable configuration defaults:
+
+ # values in %args take priority over %config_defaults
+ %config = (%config_defaults, %args);
+
=head2 Subscripts
An array can be accessed one scalar at a
@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: