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
In reply to Re: Good practice with $_ scope?
by davies
in thread Good practice with $_ scope?
by erwan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |