Walter Roberson <> wrote:
> have a traditional matching problem
> use strict;
> use warnings;
> my @ArrayF = qw(aaaa bbbb abcd ABcd);
> my $matchstring = join '|', @ArrayF;
> print grep { m/$matchstring/o } (<>)
> Note 1: as @ArrayF gets big, the backtracking involved in the matching
> can really slow you down.
If you can guarantee surrounding context, then this can be much faster..
for instance..
m/^$matchstring$/o or
m/\($matchstring\)/o
If you can't, *and* you care which one it matched, you might want to
sort the list by length first (so the longest matches are tried first).
join '|', sort {length $b <=> length $a} @ArrayF;
--
Darren Dunham
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >