Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
go ahead... be a heretic
 
PerlMonks  

Re: Matching against list of patterns

by tachyon (Chancellor)
on Sep 16, 2004 at 12:25 UTC ( #391421=note: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @terms = qw( foo bar baz fool foolish );
    my $re = join '|', map{quotemeta} sort {length($b)<=>length($a)}@terms
    +;
    ...
    skips the sort by length
    Without this foo you look foolish
    and may match short elements!
    
  2. or download this
    my %terms = ( foo => 'FOO', bar => 'BAR' );
    my $re = join '|', map{quotemeta} sort {length($b)<=>length($a)}keys %
    +terms;
    ...
    __DATA__
    foo is a word
    Bar ba blacksheep
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://391421]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2014-04-18 19:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (471 votes), past polls