in reply to (Ovid) Re: Localized Backreferences
in thread Localized Backreferences, If Statements & Blocks

It's not the scope of the if block that matters here, it's the scope of the regex. $1 is localized to the same scope. When you put the regex in that block, you enforced a more specific scope, and the behavior is more what you expect.

Apparently, the interpreter doesn't treat a regex any differently if it's in an if statement or not -- consistency is good.

In the original post, the regex was in package scope (not in an enclosing block). That means the end of the scope is the end of the file -- or the next successful backreference match which will assign something else to $1. Since the next regex doesn't match, and $1 is used before the end of the file, it still contains the last successful capture.

  • Comment on RE: (Ovid) Re: Localized Backreferences

Replies are listed 'Best First'.
RE: RE: (Ovid) Re: Localized Backreferences
by doran (Deacon) on Sep 15, 2000 at 07:38 UTC
    Ahhhhhhhhh, I see the light.
    Thank you Brother...