X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperltrap.pod;h=48a886a5f5430ed6075d4986ccb9901dd6714aff;hb=7d4807dba83f8253564940c8bb1fc36759e49187;hp=831d2d540226a63785204ca74302900c9d61550e;hpb=bf1f881789eedea18ed5f17829aaa1c73d7cf6f7;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perltrap.pod b/pod/perltrap.pod index 831d2d5..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 * @@ -672,18 +673,24 @@ operands, or output from same. =item * Numerical -Formatted output and significant digits +Formatted output and significant digits. In general, Perl 5 +tries to be more precise. For example, on a Solaris Sparc: print 7.373504 - 0, "\n"; printf "%20.18f\n", 7.373504 - 0; # Perl4 prints: - 7.375039999999996141 - 7.37503999999999614 + 7.3750399999999996141 + 7.375039999999999614 # Perl5 prints: 7.373504 - 7.37503999999999614 + 7.375039999999999614 + +Notice how the first result looks better in Perl 5. + +Your results may vary, since your floating point formatting routines +and even floating point format may be slightly different. =item * Numerical @@ -1338,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 @@ -1430,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: