in reply to Using $_ in nested loops

Better monks than I will have the real answer, but
a) local vs my; you generally mean 'my'. Local is/should be used for true global vars ($|, $/ etc) that you want to modify w/i a certain context (I want to say lexical context, but I may just mean 'block') but leave unaffected elsewhere. You'll find my/local will "work" interchangeably for far too much code but that doesn't make local the right choice.
b) I believe for loops localize $_ automagically, so you need not worry about messing w/ enclosing loops' $_ w/i and enclosed loop. You can think of local here as like a stack; enter a new loop and $_'s value get stacked, so when you exit that loop - pop! and the outer loop's $_ gets restored.

Hope that isn't 100% wrong ...

a

Replies are listed 'Best First'.
Re: Re: Using $_ in nested loops
by t'mo (Pilgrim) on Jan 12, 2001 at 18:46 UTC

    automagically

    Nice word...

    The whole idea of making a stack of $_ makes sense. Thanks!