in reply to Re: Re: $_ haters anonymou
in thread $_ haters anonymou
Or maybe we need an automatic local $_; at the beginning of each sub and in each package (which would solve some/all of what you were saying).
You could put that in all your subs where you use $_ which can be called by other things.
Then when calling other people's code enclose it in its one block:
This is the only (?) way to make absolutly sure that other code won't accidently wipe $_.#.... my $var = Package::sub; #.... # changed to #.... my $var; { local $_; $var = Package::sub; } #....
There are 4 seperate $_'s there and while they mostly don't collide you need to keep an eye on where they are all going. This could be even worse if this kind of code is mixed in with lots of other statements.$_ = 'foo'; while (<>) for (grep {/$_/} @foo) { for (map {ord($_)} split //,$_) { while (--$h{$_}>10) {print $_} } s/a/b/g; print 'middle' . $_; } print 'outer' . $_; } print $_;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Re: $_ haters anonymou
by tilly (Archbishop) on Dec 11, 2000 at 16:04 UTC | |
by dchetlin (Friar) on Dec 11, 2000 at 16:17 UTC |