in reply to Array search
First, $_ eq 'abc' is faster than /^abc$/.
If you want 0 or 1:
my $f = !!grep { $_ eq 'abc' } @a; if ($f) { ... }
True or false will probably suffice:
my $f = grep { $_ eq 'abc' } @a; if ($f) { ... }
You can get rid of the flag entirely:
if (grep { $_ eq 'abc' } @a) { ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array seach
by Aristotle (Chancellor) on Feb 20, 2006 at 00:22 UTC | |
|
Re^2: Array seach
by jeanluca (Deacon) on Feb 20, 2006 at 08:18 UTC | |
by ikegami (Patriarch) on Feb 20, 2006 at 14:52 UTC |