in reply to One line assigment statement with regex match
I tend to use something like this;
my $re = qr/(?:${\( join "|", map { qr/\Q$_\E/ } @terms )})/; ... my ($match) = ($line =~ m/($re)/);
This is especially important if your @terms contain metacharacters such as parantheses, asterix, period, etc.
Also, it is usually faster because you're only doing one regular expression match per line, not many.
$h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: One line assigment statement with regex match
by ketema (Scribe) on Jun 23, 2005 at 15:37 UTC | |
by mugwumpjism (Hermit) on Jul 06, 2005 at 22:07 UTC |