in reply to Should we Localize $_ ?

Wow!! Uhhh... I just tried out the code example from 7 Uses of local and I have to say that I'm rather concerned. It's something I've never even seen happen before, and I love my $_! Ouch ...

Replies are listed 'Best First'.
Re: Re: Should we Localize $_ ?
by mugwumpjism (Hermit) on Jun 14, 2001 at 12:13 UTC

    I can remember the first time I came across this. I had always just assumed that $_ was localised, and the book "Programming Perl" didn't even mention that it was a dangerous global.

    So I checked back through most of the complex code I was writing, found it didn't affect any of my other code, told my programming partner in cryme about it, and made a policy of not calling any functions when I was making use of $_. ie, I decided that if your loop is big enough to call functions, you should be naming the loop variable.

    I think there should be really big warnings about this, though.