On Tue, 8 Oct 2002, Faymon, Kurt wrote:

> Give a 'config file' with 100 or so entries of global subs like:
> 
> "/nli/|[nli]|<nli>","<p>"
> "/nlt/|[nlt]|<nlt>","<p1>"
> "/nlp/|[nlp]|<nlp>","<p3>"
> "/nlh/|[nlh]|<nlh>","<p2>"
> And so on...
> 
> I read these into a hash (sPiChars) with 'replace' value as key and the
> RegEx of the search terms as value of that give key. Then as I go over
> process each record in input, I check to see if one of these values present
> and then sub it if so, like:
> 
> foreach $key(keys(%sPiChars))
>                 {
>                 if($sTempRecord=~m/$sPiChars{$key}/)
>                         {
>                         $sTempRecord=~s/$sPiChars{$key}/$key/g;
>                         }

You can do away with the if statement and just write this as
$sTempRecord=~s/\b\Q$sPiChars{$key}\E\b/$key/g;
Take a look at '\b','\Q' and '\E' in perldoc perlre

For your question
perldoc -q 'How do I efficiently match many regular expressions at once?'


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to