precompiled regular expressions

mcdavis941_at_netscape.net
Date: 12/02/03

  • Next message: Todd W.: "Re: CGI - DBI"
    Date: Tue, 02 Dec 2003 08:42:58 -0500
    To: beginners@perl.org
    
    

    Hi, whats the right way to precompile a regular expression that gets used multiple times without changing.

    I don't think I can use /o, because the specific line of code which performs the pattern match is used to check various patterns against various values at various times. None the less, the patterns themselves don't change, once established, and it seems I should be able to save a precompiled regular expression in a variable and use it when it's time to match the corresponding pattern.

    The code as it stands looks like this:

       if( defined($addr) and $addr =~ /$self->{_rule}/i ) {
           $retval = $self->{_confidence};
           }

    which is an object method used with multiple object instances each having its own value for $self->{_rule}, which is why I can't use /o.

    Any help very much appreciated, and yes I am now rereading the documentation.

    __________________________________________________________________
    McAfee VirusScan Online from the Netscape Network.
    Comprehensive protection for your entire computer. Get your free trial today!
    http://channels.netscape.com/ns/computing/mcafee/index.jsp?promo=393397

    Get AOL Instant Messenger 5.1 free of charge. Download Now!
    http://aim.aol.com/aimnew/Aim/register.adp?promo=380455


  • Next message: Todd W.: "Re: CGI - DBI"

    Relevant Pages

    • Re: precompiled regular expressions
      ... whats the right way to precompile a regular expression ... > that gets used multiple times without changing. ... > the corresponding pattern. ...
      (perl.beginners)
    • Regex internal caching or what?
      ... In my application I have a need for using a regular expression now and then. ... Often the same regular expression must be used multiple times. ... It must be obvious that it takes some time to instantiate such an object. ... do I need to create my own caching functionality? ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: Regex internal caching or what?
      ... You can compile Regular Expression sinto an assembly if you like. ... Often the same regular expression must be used multiple times. ... It must be obvious that it takes some time to instantiate such an object. ... does the Regex instantiation somehow deal with some ...
      (microsoft.public.dotnet.languages.csharp)
    • Re: [opensuse] OT perl regex question
      ... It means that the regexp engine will precompile the regular expression, ... not recompile it every time the line is executed. ...
      (SuSE)
    • Re: Replace Several Items
      ... The regular expression is probably the best way to do it, ... on representative data. ... I can anticipate the results. ... replacemultiple times, it can ...
      (comp.lang.python)