Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: localization of $_

by mr.nick (Chaplain)
on Feb 28, 2001 at 00:23 UTC ( #61159=note: print w/replies, xml ) Need Help??


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")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://61159]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2023-09-22 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?