ptkFAQ
view release on metacpan or search on metacpan
history/perl425.html-pl view on Meta::CPAN
# Perl4:
7.375039999999996141
7.37503999999999614
# Perl5:
7.373504
7.37503999999999614
#############################################################################
# Example 32 - Submitted by Danny Faught
#############################################################################
# perl 4 lets you modify constants:
$foo = "x";
&mod($foo);
for ($x = 0; $x < 3; $x++) {
&mod("a");
}
sub mod {
print "before: $_[0]";
$_[0] = "m";
print " after: $_[0]\n";
}
# perl4 output:
before: x after: m
before: a after: m
before: m after: m
before: m after: m
# perl5 output:
before: x after: m
Modification of a read-only value attempted at foo.pl line 12.
before: a
#############################################################################
# Example 33 - Submitted by Danny Faught
#############################################################################
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 :-()
for (1..10) { print "Trial $_\n"; &foo('a', 'b', 'c') }
sub foo { local(@_) = ('p', 'q', 'r'); }
# This problem will be fixed in 5.003 - Bill
#############################################################################
# Example 34 - Noted in c.l.p.misc by Maurice Cinquini
#############################################################################
I've even come across old perl4 programs which
unconsciously rely on the bugs in earlier perl versions.
perl -e '$bar=q/not/; print "This is $foo{$bar} perl5"'
# perl4 prints: This is not perl5
# perl4 prints: This is perl5
#############################################################################
# Example 35 - Submitted by Markus F.X.J. Oberhumer and Danny Faught
#############################################################################
# Stricter parsing of variables used in regular expressions
s/^([^$grpc]*$grpc[$opt$plus$rep]?)//o;
# perl4: compiles w/o error
# perl5: with Scalar found where operator expected ..., near "$opt$plus"
# an added component of this example, apparantly from the same script, is
# the actual value of the s'd string after the substitution, e.g. -
$grpc = '\)';
$opt = '\?';
$plus = '\+';
$rep = '\*';
$_ = 'foo)?';
s/^([^$grpc]*${grpc}[$opt]?)/bar/;
print ;
# perl4 prints: bar
# perl5 prints: barfoo)?
#############################################################################
# Example 36 - Submitted by Kenneth Albanowski from Eric Hendrickson
#############################################################################
# Under perl5, m?x? matches only once, like ?x?. Under perl4, it matched
# repeatedly, like /x/ or m!x!.
$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";
}
# perl4 prints: perl4
# perl5 prints: perl5
#############################################################################
# Example 37 - Submitted by Jerry Whelan
#############################################################################
# parsing; note the space between . and =
$string . = "more string";
print $string;
# perl4 prints: more string
# perl5 prints: syntax error at - line 1, near ". ="
#############################################################################
# Example 38 - Submitted by Danny Faught
#############################################################################
# The behavior is slightly different for:
( run in 0.760 second using v1.01-cache-2.11-cpan-5a3173703d6 )