I would tend to turn that statement around and say that if your code relies on $_ at a higher level, and clobbering it at a lower level results in chaos, then you shouldn't be using $_ at the higher level.
It is not that easy. Clobering $_ at a lower level can easily break map, for/foreach and grep constructs at a higher level as shown at this topic: while(<>) { ... } considered harmful.
In short: would you rewrite code like
my @result = map some_sub($_), qw(a b c d);
to
my @result = map { my $x = $_; local $_; some_sub($x) } qw(a b c d);
to satisfy your requirement?
--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support
UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org
In reply to Re: Re: Using $_ as a temp var, especially in functions
by IlyaM
in thread Using $_ as a temp var, especially in functions
by BUU
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |