Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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?
[ambrus]: I don't much like highlighting matching parenthesis, because I've had some bad experiences with distracting implementations of that.

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (14)
As of 2017-02-27 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (385 votes). Check out past polls.