applied patch, with indentation tweaks
[p5sagit/p5-mst-13.2.git] / pod / perltrap.pod
index fd41f2e..4159777 100644 (file)
@@ -6,7 +6,8 @@ perltrap - Perl traps for the unwary
 
 The biggest trap of all is forgetting to use the B<-w> switch; see
 L<perlrun>.  The second biggest trap is not making your entire program
-runnable under C<use strict>.
+runnable under C<use strict>.  The third biggest trap is not reading
+the list of changes in this version of Perl; see L<perldelta>.
 
 =head2 Awk Traps
 
@@ -34,7 +35,7 @@ Curly brackets are required on C<if>s and C<while>s.
 
 =item *
 
-Variables begin with "$" or "@" in Perl.
+Variables begin with "$", "@" or "%" in Perl.
 
 =item *
 
@@ -167,7 +168,7 @@ There's no switch statement.  (But it's easy to build one on the fly.)
 
 =item *
 
-Variables begin with "$" or "@" in Perl.
+Variables begin with "$", "@" or "%" in Perl.
 
 =item *
 
@@ -437,6 +438,12 @@ whether this should be classed as a bug or not.
     # perl4 prints: x=10
     # perl5 prints: Can't find string terminator "'" anywhere before EOF
 
+You can avoid this problem, and remain compatible with perl4, if you
+always explicitly include the package name:
+
+    $x = 10 ;
+    print "x=${main'x}\n" ;
+
 Also see precedence traps, for parsing C<$:>.
 
 =item * BugFix
@@ -444,8 +451,8 @@ Also see precedence traps, for parsing C<$:>.
 The second and third arguments of C<splice()> are now evaluated in scalar
 context (as the Camel says) rather than list context.
 
-    sub sub1{return(0,2) }          # return a 2-elem array
-    sub sub2{ return(1,2,3)}        # return a 3-elem array
+    sub sub1{return(0,2) }          # return a 2-element list
+    sub sub2{ return(1,2,3)}        # return a 3-element list
     @a1 = ("a","b","c","d","e");
     @a2 = splice(@a1,&sub1,&sub2);
     print join(' ',@a2),"\n";
@@ -688,8 +695,8 @@ Logical tests now return an null, instead of 0
     # perl4 prints: 0
     # perl5 prints:
 
-Also see the L<General Regular Expression Traps using s///, etc.>
-tests for another example of this new feature...
+Also see L<"General Regular Expression Traps using s///, etc.">
+for another example of this new feature...
 
 =back
 
@@ -750,15 +757,11 @@ variable is localized subsequent to the assignment
     # perl4 prints: This is Perl 4
     # perl5 prints:
 
-    # Another example
-
-    *fred = *barney; # fred is aliased to barney
-    @barney = (1, 2, 4);
-    # @fred;
-    print "@fred";  # should print "1, 2, 4"
+=item * (Globs)
 
-    # perl4 prints: 1 2 4
-    # perl5 prints: In string, @fred now must be written as \@fred
+Assigning C<undef> to a glob has no effect in Perl 5.   In Perl 4
+it undefines the associated scalar (but may have other side effects
+including SEGVs).
 
 =item * (Scalar String)
 
@@ -922,7 +925,9 @@ Perl4-to-Perl5 traps involving precedence order.
 
 =item * Precedence
 
-LHS vs. RHS when both sides are getting an op.
+LHS vs. RHS of any assignment operator.  LHS is evaluated first
+in perl4, second in perl5; this can affect the relationship
+between side-effects in sub-expressions.
 
     @arr = ( 'left', 'right' );
     $a{shift @arr} = shift @arr;
@@ -998,18 +1003,6 @@ concatenation precedence over filetest operator?
     # perl4 prints: no output
     # perl5 prints: Can't modify -e in concatenation
 
-=item * Precedence
-
-Assignment to value takes precedence over assignment to key in
-perl5 when using the shift operator on both sides.
-
-    @arr = ( 'left', 'right' );
-    $a{shift @arr} = shift @arr;
-    print join( ' ', keys %a );
-
-    # perl4 prints: left
-    # perl5 prints: right
-
 =back
 
 =head2 General Regular Expression Traps using s///, etc.
@@ -1454,9 +1447,7 @@ Everything else.
 
 =over 5
 
-=item * Unclassified
-
-C<require>/C<do> trap using returned value
+=item * C<require>/C<do> trap using returned value
 
 If the file doit.pl has:
 
@@ -1477,6 +1468,14 @@ Running doit.pl gives the following:
 
 Same behavior if you replace C<do> with C<require>.
 
+=item * C<split> on empty string with LIMIT specified
+
+       $string = '';
+    @list = split(/foo/, $string, 2)
+
+Perl4 returns a one element list containing the empty string but Perl5
+returns an empty list.
+
 =back
 
 As always, if any of these are ever officially declared as bugs,