M
Mark
It appears that new ${*digit*} variables are not created when the same
subroutine is re-entered. Is this to be expected?
use strict ;
use warnings;
my $line = 'abc';
doit();
exit;
sub doit {
# local($1); # adding this doesn't appear to have an effect
$line =~ /(.)/ || die "no match";
print "bef \$1 =$1\n";
$line = substr($line,1);
doit() if length($line);
my $thing = $1; # WRONG! $1 has been changed by recursive call to
doit()
print "aft \$1 =$1\n";
}
Output:
bef $1 =a
bef $1 =b
bef $1 =c
aft $1 =c
aft $1 =c
aft $1 =c
Expected output:
bef $1 =a
bef $1 =b
bef $1 =c
aft $1 =c
aft $1 =b
aft $1 =a
subroutine is re-entered. Is this to be expected?
use strict ;
use warnings;
my $line = 'abc';
doit();
exit;
sub doit {
# local($1); # adding this doesn't appear to have an effect
$line =~ /(.)/ || die "no match";
print "bef \$1 =$1\n";
$line = substr($line,1);
doit() if length($line);
my $thing = $1; # WRONG! $1 has been changed by recursive call to
doit()
print "aft \$1 =$1\n";
}
Output:
bef $1 =a
bef $1 =b
bef $1 =c
aft $1 =c
aft $1 =c
aft $1 =c
Expected output:
bef $1 =a
bef $1 =b
bef $1 =c
aft $1 =c
aft $1 =b
aft $1 =a