This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
describe current behavior on local($foo{nothere}) (suggested by
authorGurusamy Sarathy <gsar@cpan.org>
Thu, 25 Mar 1999 10:33:18 +0000 (10:33 +0000)
committerGurusamy Sarathy <gsar@cpan.org>
Thu, 25 Mar 1999 10:33:18 +0000 (10:33 +0000)
Lionel Cons <lionel.cons@cern.ch>)

p4raw-id: //depot/perl@3166

pod/perlsub.pod

index 3a53573..bfab0fe 100644 (file)
@@ -581,6 +581,28 @@ Perl will print
     This is a test only a test.
     The array has 6 elements: 0, 1, 2, undef, undef, 5
 
+Note also that when you C<local>ize a member of a composite type that
+B<does not exist previously>, the value is treated as though it were
+in an lvalue context, i.e., it is first created and then C<local>ized.
+The consequence of this is that the hash or array is in fact permanently
+modified. For instance, if you say
+
+    %hash = ( 'This' => 'is', 'a' => 'test' );
+    @ary  = ( 0..5 );
+    {
+       local($ary[8]) = 0;
+       local($hash{'b'}) = 'whatever';
+    }
+    printf "%%hash has now %d keys, \@ary %d elements.\n",
+        scalar(keys(%hash)), scalar(@ary);
+
+Perl will print
+
+    %hash has now 3 keys, @ary 9 elements.
+
+The above behavior of local() on non-existent members of composite
+types is subject to change in future.
+
 =head2 Passing Symbol Table Entries (typeglobs)
 
 [Note:  The mechanism described in this section was originally the only