Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: search position is getting reset after 'local'

by Errto (Vicar)
on Jun 12, 2006 at 18:24 UTC ( [id://554866]=note: print w/replies, xml ) Need Help??


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

Based on the discussion here this appears to be a genuine bug, but I have a question: where in actual code would you bump into this scenario?
  • Comment on Re: search position is getting reset after 'local'

Replies are listed 'Best First'.
Re^2: search position is getting reset after 'local'
by Joost (Canon) on Jun 12, 2006 at 18:48 UTC
    I think the main potential problem would be when you're using localized $_ combined with m//g matches.

    let's say you convert this (working) code:

    $_ = "abcdefg"; my @some_array = (1 ..2); while (m/./g) { for (@some_array) { # implicitly localized - works # do something; } print $&; }
    to this (stupid but more or less equivalent) code:
    $_ = "abcdefg"; while (m/./g) { my @some_array = (1 ..2); while (local $_ = shift @some_array) { # manually localized - break +s # do something; } print $&; }

    Some of the parsing code i've written makes heavy use of $_ and then you can run into this problem when you're refactoring.

    update: the above code breaks, because it's not the pos() function that's broken, but the match position field itself gets reset by localizing a variable - in other words, the while (m/./g) statement will loop forever.

Re^2: search position is getting reset after 'local'
by Fletch (Bishop) on Jun 12, 2006 at 18:42 UTC

    Not an actual usage, but I could easily see something which did a match, called a sub which localized $_, and then tried to use pos() after that sub returned. Granted it'd be kinda sloppy code (like depending on $1 and friends to remain set rather than saving values off if you need to use them), but again I could see it happening.

Re^2: search position is getting reset after 'local'
by ikegami (Patriarch) on Jun 12, 2006 at 18:38 UTC
    I don't remember what I was doing, but I encountered this bug before. It was possibly in some kind of lexer or parser.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-16 19:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found