in reply to Re^4: Problem with regexp or saved match variable.
in thread Problem with regexp or saved match variable.

Ah, I hadn't grokked the effect of the continue block. I agree, if this is all "as intended", it's not at all clear from the documenatation.

The unfortunate first-letter collision of lexical and local has tripped up almost everyone at some point or another, I think.

  • Comment on Re^5: Problem with regexp or saved match variable.

Replies are listed 'Best First'.
Re^6: Problem with regexp or saved match variable.
by ig (Vicar) on Aug 27, 2009 at 21:03 UTC

    Also, the difficulty of using local (in any of its grammatical forms) without wanting to imply the local function frustrates me, and confuses me when others do so without being explicit.

    The following passage from perlsyn is an example that mislead me, and I suspect others, until I realized that local means local but localized means my and localization refers ambiguously to both local or my. It is very difficult for me not to see the local function all three times - I trip on this every time I read the passage.

    The "foreach" loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword "my", then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with "my", it uses that variable instead of the global one, but it’s still localized to the loop. This implicit localisation occurs only in a "foreach" loop.