felipe has asked for the wisdom of the Perl Monks concerning the following question:
Is there any way to name the $_ variable in grep?
For instance, in a foreach loop, we can use $_ like this:
foreach (@array) { dosomething($_); }
I can avoid by "naming" it, just like this:
foreach my $element (@array) { dosomething($element); }
Let's go to the point. In a grep statement, I have something like this:
my @array_2 = grep {$_->func eq 'TEST'} @array_1;I would really like to name the $_ because I do scripts for biologists and sometimes they modify scripts and they always get lost with $_. Is there any simple way to accomplish this?
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to avoid $_ in grep
by GrandFather (Saint) on Nov 13, 2007 at 21:41 UTC | |
|
Re: How to avoid $_ in grep
by gamache (Friar) on Nov 13, 2007 at 20:47 UTC | |
by agianni (Hermit) on Nov 13, 2007 at 20:54 UTC | |
by gamache (Friar) on Nov 13, 2007 at 21:13 UTC | |
|
Re: How to avoid $_ in grep
by blahblahblah (Priest) on Nov 14, 2007 at 03:06 UTC | |
by Krambambuli (Curate) on Nov 14, 2007 at 09:39 UTC | |
by felipe (Initiate) on Nov 14, 2007 at 14:27 UTC | |
|
Re: How to avoid $_ in grep
by lupey (Monk) on Nov 13, 2007 at 21:00 UTC | |
by ikegami (Patriarch) on Nov 13, 2007 at 21:10 UTC |