ptkFAQ
view release on metacpan or search on metacpan
history/perl425.html view on Meta::CPAN
print ++$x," : ";
print -$x," : ";
print ++$x,"\n";</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>aab : -0 : 1</XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>aab : -aab : aac</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 30 - Submitted by Simon Chatterjee</H2>
<P><CODE>s`lhs`rhs`</CODE> is now a normal substitution, with no backtick
expansion
<XMP>
$string = "";
$string =~ s`^`hostname`;
print $string, "\n";</XMP><DL><DT><I>perl4 prints:</I><DD><XMP><the local hostname></XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>hostname</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 31 - Submitted by Simon Chatterjee</H2>
<P>Formatted output and significant digits
<XMP>
print 7.373504 - 0, "\n";
printf "%20.18f\n", 7.373504 - 0;</XMP><DL><DT><I>Perl4:</I><DD><XMP></XMP></DL><XMP>
7.375039999999996141
7.37503999999999614</XMP><DL><DT><I>Perl5:</I><DD><XMP></XMP></DL><XMP>
7.373504
7.37503999999999614</XMP><P>
<HR><H2>Example 32 - Submitted by Danny Faught</H2>
<P>perl 4 lets you modify constants:
<XMP>
$foo = "x";
&mod($foo);
for ($x = 0; $x < 3; $x++) {
&mod("a");
}
sub mod {
print "before: $_[0]";
$_[0] = "m";
print " after: $_[0]\n";
}</XMP><DL><DT><I>perl4 output:</I><DD><XMP></XMP></DL><XMP> before: x after: m
before: a after: m
before: m after: m
before: m after: m</XMP><DL><DT><I>perl5 output:</I><DD><XMP></XMP></DL><XMP> before: x after: m
Modification of a read-only value attempted at foo.pl line 12.
before: a</XMP><P>
<HR><H2>Example 33 - Submitted by Danny Faught</H2>
<P>Just a quick note to say that localizing @_ has always been broken
in perl5 (especially where defgv is involved in other guises). Try
this from my 5.001m collection (I don't believe I ever took the time
to report this :-()
<XMP>
for (1..10) { print "Trial $_\n"; &foo('a', 'b', 'c') }
sub foo { local(@_) = ('p', 'q', 'r'); }</XMP>This problem will be fixed in 5.003 - Bill
<XMP></XMP><P>
<HR><H2>Example 34 - Noted in c.l.p.misc by Maurice Cinquini </H2>
<P>I've even come across old perl4 programs which
unconsciously rely on the bugs in earlier perl versions.
<XMP>
perl -e '$bar=q/not/; print "This is $foo{$bar} perl5"'</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>This is not perl5</XMP></DL>
<DL><DT><I>perl4 prints:</I><DD><XMP>This is perl5</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 35 - Submitted by Markus F.X.J. Oberhumer and Danny Faught</H2>
<P>Stricter parsing of variables used in regular expressions
<XMP>
s/^([^$grpc]*$grpc[$opt$plus$rep]?)//o;</XMP><DL><DT><I>perl4:</I><DD><XMP>compiles w/o error</XMP></DL>
<DL><DT><I>perl5:</I><DD><XMP>with Scalar found where operator expected ..., near "$opt$plus"</XMP></DL>
<XMP></XMP>an added component of this example, apparantly from the same script, is
the actual value of the <CODE>s'd</CODE> string after the substitution, e.g. -
<XMP>
$grpc = '\)';
$opt = '\?';
$plus = '\+';
$rep = '\*';
$_ = 'foo)?';
s/^([^$grpc]*${grpc}[$opt]?)/bar/;
print ;</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>bar</XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>barfoo)?</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 36 - Submitted by Kenneth Albanowski from Eric Hendrickson</H2>
<P>Under perl5, <CODE>m?x?</CODE> matches only once, like ?x?. Under perl4, it matched
repeatedly, like /x/ or <CODE>m!x!.</CODE>
<XMP>
$test = "once";
sub match { $test =~ m?once?; }
&match();
if ( &match() ) {
# m?x? matches more then once
print "perl4\n";
} else {
# m?x? matches only once
print "perl5\n";
}</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>perl4</XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>perl5</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 37 - Submitted by Jerry Whelan</H2>
<P>parsing; note the space between . and =
<XMP>
$string . = "more string";
print $string;</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>more string</XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>syntax error at - line 1, near ". ="</XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 38 - Submitted by Danny Faught</H2>
<P>The behavior is slightly different for:
<XMP>
print "$x", defined $x</XMP><DL><DT><I>perl4:</I><DD><XMP>1</XMP></DL>
<DL><DT><I>perl5:</I><DD><XMP><no output, $x is not called into existence></XMP></DL>
<XMP></XMP><P>
<HR><H2>Example 39 - Submitted by Danny Faught</H2>
<P>You also have to be careful about array references:
This may be related to example 24
<XMP>
print "$foo{"</XMP><DL><DT><I>perl4 prints:</I><DD><XMP>{</XMP></DL>
<DL><DT><I>perl5 prints:</I><DD><XMP>syntax error</XMP></DL>
<XMP></XMP><P>
( run in 0.877 second using v1.01-cache-2.11-cpan-98e64b0badf )