GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  REGEX::PRESUF (3)

.ds Aq ’

NAME

Regex::PreSuf - create regular expressions from word lists

CONTENTS

SYNOPSIS



        use Regex::PreSuf;
       
        my $re = presuf(qw(foobar fooxar foozap));

        # $re should be now foo(?:zap|[bx]ar)



DESCRIPTION

The <B>B>presuf()<B>B> subroutine builds regular expressions out of ’word lists’, lists of strings. The regular expression matches the same words as the word list. These regular expressions normally run faster than a simple-minded ’|’-concatenation of the words.

Examples:
o



        foobar fooxar => foo[bx]ar



o



        foobar foozap => foo(?:bar|zap)



o



        foobar fooar  => foob?ar



The downsides:
o The original order of the words is not necessarily respected, for example because the character class matches are collected together, separate from the ’|’ alternations.
o The module blithely ignores any specialness of any regular expression metacharacters such as the .*?+{}[]^$, they are just plain ordinary boring characters.
For the second downside there is an exception. The module has some rudimentary grasp of how to use the ’any character’ metacharacter. If you call <B>B>presuf()<B>B> like this:



        my $re = presuf({ anychar=>1 }, qw(foobar foo.ar fooxar));

        # $re should be now foo.ar



The module finds out the common prefixes and suffixes of the words and then recursively looks at the remaining differences. However, by default only common prefixes are used because for many languages (natural or artificial) this seems to produce the fastest matchers. To allow also for suffixes use



        my $re = presuf({ suffixes=>1 }, ...);



To use <B>onlyB> suffixes use



        my $re = presuf({ prefixes=>0 }, ...);



(this implicitly enables suffixes)

    Debugging

In case you want to flood your session without debug messages you can turn on debugging by saying



        Regex::PreSuf::debug(1);



How to turn them off again is left as an exercise for the kind reader.

COPYRIGHT

Jarkko Hietaniemi

This code is distributed under the same copyright terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 PRESUF (3) 2006-02-26

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.