Delano > Regexp-Match-List-0.5 > Regexp::Match::List

Download:
Regexp-Match-List-0.5.tar.gz

Dependencies

Annotate this POD (1)

View/Report Bugs
Module Version: 0.5   Source  

NAME ^

Regexp::Match::List - Matches a string to a list of regular expressions

SYNOPSIS 1 (short) ^

    my $re = Regexp::Match::List->new( 
        DEBUG     => 1,               #   share debugging output (caught by Class::Base)
        OPCHECK   => 100,             #   how often to reoptimize regexps 
        OPSKIP    => 0,               #   Skip optimize()?
        OPWEIGHT  => 1,               #   default regexp hit multiplier
        OPSORTSUB => sub { ... },     #   sorting algorithm used by optimize()
    );

    $re->add('(?i:(trans)(\w\w\w)(tite))', weight => 1.5, hits => 0, somekey => somevalue );

    #   $RE contains the configured regular expression that successfully matched
    #   the string. You have access to $RE->{'weight'}, $RE->{'callback'}, 
    #   $RE->{'somekey'}, etc... 
    #   @results contains the m// for paired parentheses. In the example below, 
    #   it would contain ('trans','ves','tite');
    my ($RE, @results) = $re->match('transvestite ');
    
    #   Callback template:
    sub somesub($@) 
    #   This callback is called regardless of whether the regular expression
    #   matched the string. Returning any true value will tell match() that 
    #   this was a success. Any non-true value will admit failure.
    {
        my ($RE, @results) = @_;   
       
        # ... do something
        # here you can add more criteria for a particular match
        #   
       
        #   Here we maintain the same return value that match() would
        #   return on. Any true value will tell match() this match was
        #   a smashing success.
        return $#results >= 0; 
        
        #   If we did this, all matches would be considered unsuccessful
        #   return 0;
    }

DESCRIPTION ^

    Regexp::Match::List matches a string to a list of regular expressions
    with callbacks and sorting optimization for large datasets.
    Think Regexp::Match::Any with optimization (sort on usage trends, most 
    popular first -- see Data::Sorting) and expanded functionality.
    
    
    note: all parameters are stored in an RE object and returned on a positive match
    note: the callback is called for every regexp test (successful or not)
         so it gets the final say as to whether or not there was a match
    note: the callback is given the RE object. (see bottom the example above)

STABILITY ^

This module is currently undergoing rapid development and there is much left to do. This module is beta-quality, although it hasn't been extensively tested or optimized.

It has been tested only on Solaris 8 (SPARC64).

KNOWN BUGS ^

None

SEE ALSO ^

Regexp::Match::Any, Regexp::Common, Data::Sorting, Class::Base

AUTHOR ^

Delano Mandelbaum, <horrible<AT>murderer.ca>

COPYRIGHT AND LICENSE ^

Copyright (C) 2004 by Delano Mandelbaum

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html

syntax highlighting: