Bingo! It is as I suspected in my initial post. I was confused in my latter posts because I was looking at the wrong version.
Changes to $1 results in changes to $_[1], since $_[1] is aliased to $1. I was looking at the version in perl-5.10.0, not the one from PathTools-3.2701. The one in perl-5.10.0 copies @_ into local variables, so it works fine. The one in Pathtools-3.2701 works with @_ directly, so it picks up the change to $1.
That technically makes the bug PathTools's, since it should localize the globlals it modifies (like $1). However, it's rarely done (especially for $1, $! and $@) and it's actually rather hard to do when working with @_ directly and package variables (like $1), so it's best not to pass globals to functions and to follow the tips I already posted.
Update: Here's some code the illustrate the issue.
sub f_bad { 'b' =~ /(.*)/; return $_[0]; }
sub f_good1 { my ($var) = @_; 'b' =~ /(.*)/; return $var; }
sub f_good2 { { local $1; 'b' =~ /(.*)/; } return $_[0]; }
'a' =~ /(.*)/; print f_bad($1), "\n"; # b
'a' =~ /(.*)/; print f_good1($1), "\n"; # a
'a' =~ /(.*)/; print f_good2($1), "\n"; # a
Unforunately, sub { local $1; 'b' =~ /(.*)/; return $_[0]; } doesn't work since local doesn't create a new variable.
|