rir has asked for the wisdom of the Perl Monks concerning the following question:
Update: I'd downvote this if I could. My error was thinking $a and $b when
$_ was appropriate.
rir
The recent thread, Better algorithm or data structure?, shows that this behavior of $_ is not well known. It surprised me. It took prompting for this aspect to register (thanks, BrowserUk).
Update: reduced code to the point. This expresses that to which I was referring. Map and grep, like for can, localize $_; this makes this post nonsensical;
Be well,## perl 5.10.1 use strict; use warnings; my $oo; my @ary = ( 0, 1, 2, 3); grep $ary[$_ ], @ary; # no warning grep $ary[$oo], @ary; # warns
rir
Original verbose code:
<Reveal this spoiler or all in this thread>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: uninitialized $_ sneaks past warnings in grep/map block or expression
by merlyn (Sage) on Sep 01, 2010 at 13:39 UTC | |
by ikegami (Patriarch) on Sep 01, 2010 at 14:05 UTC | |
Re: uninitialized $_ sneaks past warnings in grep/map block or expression
by AnomalousMonk (Archbishop) on Sep 01, 2010 at 14:01 UTC | |
Re: uninitialized $_ sneaks past warnings in grep/map block or expression
by mr_mischief (Monsignor) on Sep 01, 2010 at 14:09 UTC | |
by JavaFan (Canon) on Sep 01, 2010 at 16:00 UTC | |
by mr_mischief (Monsignor) on Sep 01, 2010 at 16:05 UTC |
Back to
Seekers of Perl Wisdom