[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] Parsing a Text File



Chris St. Pierre wrote:
my $ra = Regexp::Assemble->new();
foreach (@regexps) {
  $ra->add($_);
}
my $re = $ra->re;

Ooo! That's slick! I was going to suggest using qr//o to compile each regex once and only once, then a foreach loop.

perldoc perlop
   qr/STRING/imosx
$0.02,

j


----------------------------------
my @res = (
  qr/AAA/,
  qr/BBB/,
  qr/CCC/
);

while (<DATA>) {
  foreach my $re (@res) {
     ($_ =~ $re) && print && last;
  }
}

__DATA__
blah
blAAAh
blCCCh
blah