This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #99382] 'stat' call documentation is poorly worded
[perl5.git] / pod / perldata.pod
index 977c0e0..9bff98f 100644 (file)
@@ -232,8 +232,7 @@ which is a different value since there is ordinarily a 0th element.
 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
@@ -355,8 +354,8 @@ C<$who::0>, and a C<$who's> variable.  The last two would be the
 $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
@@ -666,6 +665,29 @@ Note that just because a hash is initialized in that order doesn't
 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
@@ -755,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: