FAQ 6.16: How do I efficiently match many regular expressions at once? 
Author Message
 FAQ 6.16: How do I efficiently match many regular expressions at once?

(This excerpt from perlfaq6 - Regexes
    ($Revision: 1.27 $, $Date: 1999/05/23 16:08:30 $)
part of the standard set of documentation included with every
valid Perl distribution, like the one on your system.
See also http://www.*-*-*.com/
if your negligent system adminstrator has been remiss in his duties.)

  How do I efficiently match many regular expressions at once?

    The following is extremely inefficient:

        # slow but obvious way

        while (defined($line = <>)) {

                if ($line =~ /\b$state\b/i) {  
                    print $line;
                    last;
                }
            }
        }                                        

    That's because Perl has to recompile all those patterns for each of
    the lines of the file. As of the 5.005 release, there's a much
    better approach, one which makes use of the new `qr//' operator:

        # use spiffy new qr// operator, with /i flag even
        use 5.005;


        while (defined($line = <>)) {

                print $line if $line =~ /$patobj/;
            }
        }

--
Fine, let them give me the endless crap.   --Andrew Hume



Fri, 23 Nov 2001 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. FAQ 6.16: How do I efficiently match many regular expressions at once?

2. FAQ 6.16: How do I efficiently match many regular expressions at once?

3. FAQ 6.16: How do I efficiently match many regular expressions at once?

4. FAQ 6.16: How do I efficiently match many regular expressions at once?

5. FAQ 6.16: How do I efficiently match many regular expressions at once?

6. FAQ 6.16: How do I efficiently match many regular expressions at once?

7. FAQ 6.16: How do I efficiently match many regular expressions at once?

8. FAQ 6.16 How can I do approximate matching?

9. FAQ 6.16 How can I do approximate matching?

10. FAQ 6.16 How can I do approximate matching?

11. FAQ 6.16 How can I do approximate matching?

12. FAQ 6.16 How can I do approximate matching?

 

 
Powered by phpBB® Forum Software