in reply to lsearch for perl?
$found = 0; @list = grep { $item ne $_ || $found++ } @list;
or
my ($index) = grep { $item eq $list[$_] } 0..$#list; splice(@list, $index, 1) if defined $index;
or
use List::Util qw( first ); my $index = first { $item eq $list[$_] } 0..$#list; splice(@list, $index, 1) if defined $index;
Update: Tested. Fixed flawed grep rule.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: lsearch for perl?
by shenme (Priest) on Dec 05, 2005 at 17:50 UTC | |
Re^2: lsearch for perl?
by matt.tovey (Beadle) on Dec 06, 2005 at 08:52 UTC | |
by ikegami (Patriarch) on Dec 06, 2005 at 15:33 UTC |
In Section
Seekers of Perl Wisdom