From: "Faymon, Kurt" <[EMAIL PROTECTED]>

> 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;
>                         }
>                 }
> 
> Which works, but it really kinda slows things down. Willing to admit
> that it's a small miracle I even got this to work, I'm guessing there
> is a better way to deal with many subs with RegEx; any clued as to
> which paths I should wander down in terms of increasing the efficiency
> of this?

1) Compile the regexps when you are storing them:

        ...
        $sPiChars{$replace} = qr/$regexp/;
        ...

the rest of the code may stay the same.

2) Why do you first test whether the regexp matches and then replace?

        foreach $key(keys(%sPiChars)) {
                $sTempRecord =~ s/$sPiChars{$key}/$key/g;
        }

or (if you need to dome something more in case it matched)

        foreach $key(keys(%sPiChars)) {
                if($sTempRecord =~ s/$sPiChars{$key}/$key/g) {
                        ...
                }
        }

HTH, Jenda
=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
                                        --- me


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

Reply via email to