in reply to Regex and question of design

If you have a few regex to apply to each line an array of pre-compiled regex is about the most optimimum you are going to get if you need to know which regex matched. If you only care about the fact one did match you could construct one super regex to rule them all but that could be dificult.

#!/usr/bin/perl use strict; use warnings; my @regex; while (<DATA>) { chomp; push @regex, qr/$_/; } while (my $line = <STDIN>) { for (0..$#regex) { print "matched no: $_\n" if $line=~/$regex[$_]/; } } __DATA__ foo bar baz

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^2: Regex and question of design
by Anonymous Monk on Apr 14, 2005 at 11:31 UTC
    I've already quite the same script ;-)
    Thanks to remember me the existence of qr// !