X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperltrap.pod;h=48a886a5f5430ed6075d4986ccb9901dd6714aff;hb=7d4807dba83f8253564940c8bb1fc36759e49187;hp=06ddb19bfca2d2fe1f94fbee5a20278e3729df56;hpb=a9709c401855e2988a7d96164a23d12b6bf4a06a;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perltrap.pod b/pod/perltrap.pod index 06ddb19..48a886a 100644 --- a/pod/perltrap.pod +++ b/pod/perltrap.pod @@ -143,9 +143,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 +159,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 * @@ -1344,13 +1345,12 @@ within certain expressions, statements, contexts, or whatever. =item * Interpolation -Double-quoted strings may no longer end with an unescaped $ or @. +Double-quoted strings may no longer end with an unescaped $. $foo = "foo$"; - $bar = "bar@"; - print "foo is $foo, bar is $bar\n"; + print "foo is $foo\n"; - # perl4 prints: foo is foo$, bar is bar@ + # perl4 prints: foo is foo$ # perl5 errors: Final $ should be \$ or $name Note: perl5 DOES NOT error on the terminating @ in $bar @@ -1436,13 +1436,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: