Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: search position is getting reset after 'local'

by Joost (Canon)
on Jun 12, 2006 at 11:51 UTC ( [id://554786]=note: print w/replies, xml ) Need Help??


in reply to search position is getting reset after 'local'

I think this should clear things up a bit (from perlsub):
A "local" just gives temporary values to global (meaning package) variables. It does not create a local variable.
I read that as meaning it works like this:
print "$x, ", pos($x), "\n"; { $tmp_1 = $x; $x = undef; $x = $tmp_1; # assign "old" value to $x, losing the pos() informat +ion. } print "$x, ", pos($x), "\n";

Replies are listed 'Best First'.
Re^2: search position is getting reset after 'local'
by dave_the_m (Monsignor) on Jun 12, 2006 at 12:51 UTC
    No, local is more close to this:
    { $orig_value = \$x; *x = \$tmp_new_value; ....; *x = $orig_value; }

    and the OP has reported a genuine bug

    Dave.

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://554786]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-25 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found