X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperltrap.pod;h=02abc3b03b3852526578fb132c30c56fb6e2ee66;hb=ce3f0a3cd6f30cb49f01b7811c2891acb7bab15a;hp=fd41f2ef4d6e3baf052c614832ed308e0a4f49bf;hpb=54310121b442974721115f93666234a200f5c7e4;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perltrap.pod b/pod/perltrap.pod index fd41f2e..02abc3b 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -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. The second biggest trap is not making your entire program -runnable under C. +runnable under C. The third biggest trap is not reading +the list of changes in this version of Perl; see L. =head2 Awk Traps @@ -34,7 +35,7 @@ Curly brackets are required on Cs and Cs. =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 @@ -688,8 +695,8 @@ Logical tests now return an null, instead of 0 # perl4 prints: 0 # perl5 prints: -Also see the L -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 @@ -922,7 +929,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 +1007,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 +1451,7 @@ Everything else. =over 5 -=item * Unclassified - -C/C trap using returned value +=item * C/C trap using returned value If the file doit.pl has: @@ -1477,6 +1472,14 @@ Running doit.pl gives the following: Same behavior if you replace C with C. +=item * C 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,