Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 %
    foo is a word
    Bar ba blacksheep

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2016-10-27 22:48 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (372 votes). Check out past polls.