in reply to Re: Using $_ as a temp var, especially in functions
in thread Using $_ as a temp var, especially in functions
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re:x3 Using $_ as a temp var, especially in functions
by grinder (Bishop) on Oct 23, 2002 at 13:19 UTC | |
by IlyaM (Parson) on Oct 23, 2002 at 13:49 UTC | |
by IlyaM (Parson) on Aug 07, 2003 at 07:34 UTC |