in reply to localization of $_

If you use $_ often as a temporary variable, you should definately use local $_; at the beginning of your subroutines to prevent this exact situation from happening.

Replies are listed 'Best First'.
(tye)Re: localization of $_
by tye (Sage) on Feb 28, 2001 at 00:40 UTC

    ...and you can also be defensive and protect yourself from other code that isn't as nice:

    sub mine { local( $_ ); while( <FILE> ) { s/this/that/g; { local( $_ )= $_; yours( $_ ); } s/that/this/g; }
    though if you find yourself doing that I strongly suggest you just switch to using my $var instead of $_.

            - tye (but my friends call me "Tye")