http://www.perlmonks.org?node_id=930730


in reply to Is there a way around grep?

if (grep {$_ eq $filename} @index_file_names) {

is basically the same as

my $found; for (@index_file_names) { ++$found if $_ eq $filename; } if ($found) {

grep

Replies are listed 'Best First'.
Re^2: Is there a way around grep?
by suaveant (Parson) on Oct 11, 2011 at 15:53 UTC
    Of course, if only looking for a match a good addition would be a last to break the loop as soon as a match is found.

    Or use List::Util::first

                    - Ant
                    - Some of my best work - (1 2 3)

      If you're looking for speed, I bet grep is normally faster than for+last.