[ID 20000817.018] behaviour change 5.5.3 -> 5.6.0 re "Modification of a read-only...
authorPaul David Fardy <pdf@morgan.ucs.mun.ca>
Thu, 17 Aug 2000 17:23:40 +0000 (14:53 -0230)
committerJarkko Hietaniemi <jhi@iki.fi>
Fri, 18 Aug 2000 13:26:14 +0000 (13:26 +0000)
Message-Id: <200008171953.RAA17673@porthos.ucs.mun.ca>

p4raw-id: //depot/perl@6696

pod/perldiag.pod
pod/perlsyn.pod

index b55c7df..6f62e3c 100644 (file)
@@ -1865,6 +1865,14 @@ catches that.  But an easy way to do the same thing is:
 
 Another way is to assign to a substr() that's off the end of the string.
 
+Yet another way is to assign to a C<foreach> loop I<VAR> when I<VAR>
+is aliased to a constant in the look I<LIST>:
+
+        $x = 1;
+        foreach my $n ($x, 2) {
+            $n *= 2; # modifies the $x, but fails on attempt to modify the 2
+        } 
+
 =item Modification of non-creatable array value attempted, %s
 
 (F) You tried to make an array value spring into existence, and the
index 6d820b6..e6b420e 100644 (file)
@@ -309,9 +309,12 @@ The C<foreach> keyword is actually a synonym for the C<for> keyword, so
 you can use C<foreach> for readability or C<for> for brevity.  (Or because
 the Bourne shell is more familiar to you than I<csh>, so writing C<for>
 comes more naturally.)  If VAR is omitted, C<$_> is set to each value.
-If any element of LIST is an lvalue, you can modify it by modifying VAR
-inside the loop.  That's because the C<foreach> loop index variable is
-an implicit alias for each item in the list that you're looping over.
+
+If any element of LIST is an lvalue, you can modify it by modifying
+VAR inside the loop.  Conversely, if any element of LIST is NOT an
+lvalue, any attempt to modify that element will fail.  In other words,
+the C<foreach> loop index variable is an implicit alias for each item
+in the list that you're looping over.
 
 If any part of LIST is an array, C<foreach> will get very confused if
 you add or remove elements within the loop body, for example with