H
Heinrich Mislik
Hello,
this program
#!/usr/bin/perl
use warnings;
use strict;
'a' =~ m/(.)/;
warn $1;
unter($1);
warn $1;
sub unter
{
warn $_[0];
'b' =~ m/(.)/;
warn $_[0];
}
__END__
outputs:
a at ./demo.pl line 7.
a at ./demo.pl line 13.
b at ./demo.pl line 15.
a at ./demo.pl line 9.
This means, the value of $_[0] changes during evaluation of the regex
in the subroutine. Even considering $_[0] is an alias to $1, this should
not happen. This looks like entering the sub happens as follows:
1.) Make local copy of $1.
2.) Make $_[0] an alias to $1 (the local copy of $1)
This should be the other way round:
1.) Make $_[0] alias to $1 (the outer $1)
2.) Make local copy of $1.
perl -v
This is perl, v5.10.0 built for cygwin-thread-multi-64int
(with 6 registered patches, see perl -V for more detail)
Cheers
Heinrich
this program
#!/usr/bin/perl
use warnings;
use strict;
'a' =~ m/(.)/;
warn $1;
unter($1);
warn $1;
sub unter
{
warn $_[0];
'b' =~ m/(.)/;
warn $_[0];
}
__END__
outputs:
a at ./demo.pl line 7.
a at ./demo.pl line 13.
b at ./demo.pl line 15.
a at ./demo.pl line 9.
This means, the value of $_[0] changes during evaluation of the regex
in the subroutine. Even considering $_[0] is an alias to $1, this should
not happen. This looks like entering the sub happens as follows:
1.) Make local copy of $1.
2.) Make $_[0] an alias to $1 (the local copy of $1)
This should be the other way round:
1.) Make $_[0] alias to $1 (the outer $1)
2.) Make local copy of $1.
perl -v
This is perl, v5.10.0 built for cygwin-thread-multi-64int
(with 6 registered patches, see perl -V for more detail)
Cheers
Heinrich