Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: search position is getting reset after 'local' (Workaround)

by ikegami (Patriarch)
on Jun 12, 2006 at 22:27 UTC ( [id://554915]=note: print w/replies, xml ) Need Help??


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

There is a workaround:

#!/usr/bin/perl -w $x = "123 56"; $x =~ / /g; print "$x, ", pos($x), "\n"; { local *x } # <--- print "$x, ", pos($x), "\n";

The catch: @x, %x, &x, etc will get localized too. In other words, if you use local *_ to protect the pos of $_, you will lose access to the current @_ for the remainder of block.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-29 08:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found