Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Good practice with $_ scope?

by davies (Prior)
on Jun 12, 2016 at 14:53 UTC ( [id://1165423]=note: print w/replies, xml ) Need Help??


in reply to Good practice with $_ scope?

If you don't have standards telling you when to do these things (if, like me, you are coding for your own fun & education or if you are a one man shop), then you should do what fits your brain. If you find it clearer to localise $_ every time, go ahead. My attitude is that, if there is the slightest possibility of confusion, I assign to a named variable rather than use $_. So part of your code might, in my idiom, become:

use Modern::Perl; my $res; while ($res = <DATA>) { chomp $res; say $res . "***"; } __DATA__ 1234 qwer asdf zxcv

But if you are working alongside anyone else, ask them what they do or, if they are unfamiliar with the construct, what they find clearest. They may have to maintain your code or you theirs. In either case, it would be better if you had a common style and understood each other's idioms.

Regards,

John Davies

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2024-04-26 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found