X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperltrap.pod;h=d8f667c736abf3964cb3a10f8d8ac2399579fbf5;hb=4e9dada01dea61250de18f52c49ec01866133705;hp=d06f84ff804a76b633dbc25c09f6c284db142662;hpb=1fa58becc2b101b3968cca02b977c50896c15fc5;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perltrap.pod b/pod/perltrap.pod index d06f84f..d8f667c 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -18,6 +18,11 @@ Accustomed B users should take special note of the following: =item * +A Perl program executes only once, not once for each input line. You can +do an implicit loop with C<-n> or C<-p>. + +=item * + The English module, loaded via use English; @@ -143,9 +148,9 @@ gives you. =back -=head2 C Traps +=head2 C/C++ Traps -Cerebral C programmers should take note of the following: +Cerebral C and C++ programmers should take note of the following: =over 4 @@ -159,13 +164,14 @@ You must use C rather than C. =item * -The C and C keywords from C become in -Perl C and C, respectively. -Unlike in C, these do I work within a C construct. +The C and C keywords from C become in Perl C +and C, respectively. Unlike in C, these do I work within a +C construct. See L. =item * -There's no switch statement. (But it's easy to build one on the fly.) +There's no switch statement. (But it's easy to build one on the fly, +see L) =item * @@ -173,7 +179,9 @@ Variables begin with "$", "@" or "%" in Perl. =item * -Comments begin with "#", not "/*". +Comments begin with "#", not "/*" or "//". Perl may interpret C/C++ +comments as division operators, unterminated regular expressions or +the defined-or operator. =item * @@ -205,6 +213,11 @@ Seasoned B programmers should take note of the following: =item * +A Perl program executes only once, not once for each input line. You can +do an implicit loop with C<-n> or C<-p>. + +=item * + Backreferences in substitutions use "$" rather than "\". =item * @@ -1223,6 +1236,10 @@ repeatedly, like C or C. # perl4 prints: perl4 # perl5 prints: perl5 +=item * Regular Expression + +Unlike in Ruby, failed matches in Perl do not reset the match variables +($1, $2, ..., C<$`>, ...). =back @@ -1435,13 +1452,26 @@ perl4 programs which unconsciously rely on the bugs in earlier perl versions. =item * Interpolation -You also have to be careful about array references. +You also have to be careful about array and hash brackets during +interpolation. + + print "$foo[" + + perl 4 prints: [ + perl 5 prints: syntax error print "$foo{" perl 4 prints: { perl 5 prints: syntax error +Perl 5 is expecting to find an index or key name following the respective +brackets, as well as an ending bracket of the appropriate type. In order +to mimic the behavior of Perl 4, you must escape the bracket like so. + + print "$foo\["; + print "$foo\{"; + =item * Interpolation Similarly, watch out for: