in reply to Re: Map function slowing down program
in thread Map function slowing down program

That should be grep (I also favor using an array rather than a hash):
>perl -wMstrict -le "my @strs = qw( ab cd ef gh ); my @rxs = map qr{ \Q$_\E }xms, @strs; my $line = 'xxabyyefzzghhh'; my $cnt = grep $line =~ $_, @rxs; print $cnt; " 3

Replies are listed 'Best First'.
Re^3: Map function slowing down program
by jwkrahn (Abbot) on Nov 17, 2008 at 03:32 UTC

    It works with map as well as with grep.   Try it and see.

      Yes and no. With map, it depends on the pattern.
      >perl -le"@rxs='(.)(.)'; $line = 'ab'; my $cnt = grep $line =~ $_, @rx +s; print $cnt" 1 >perl -le"@rxs='(.)(.)'; $line = 'ab'; my $cnt = map $line =~ $_, @rxs +; print $cnt" 2

      grep is more robust. It'll work with just about any expression, whereas map only works with very specific expressions.