Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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 drinking their drinks and smoking their pipes about the Monastery: (13)
As of 2015-11-24 23:05 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (665 votes), past polls