in reply to Re^2: search position is getting reset after 'local'
in thread search position is getting reset after 'local'

It's a bug, yes. I'm wondering what's wrong with local() then, since your equivalent does work as you would expect local to act:
$x = 'abc de'; $x =~ m/ /g; print "1=",pos $x; { $orig_value = \$x; *x = \$tmp_new_value; print " 2=".pos $x; # ....; *x = $orig_value; } print " 3=".pos $$orig_value; print " 4=".pos $x;
output:
1=4 2= 3=4 4=4

Replies are listed 'Best First'.
Re^4: search position is getting reset after 'local'
by dave_the_m (Monsignor) on Jun 12, 2006 at 13:35 UTC
    I'm wondering what's wrong with local() then, since your equivalent does work as you would expect local to act
    It's to do with how magic attached to the value (eg pos magic) is sometimes copied to the new value, and sometimes copied back at the end. For example, a localised %ENV still needs to affect environment variables.

    It's on my Big List of Things To Fix At Some Point.

    Dave.