Martin,

I recommend you keep the regex more detailed so you don't match on, for
instance, 'yahoo.com?q=google' and so on.

my $string = 'google.com?q=yahoo+ask.com+msn';

my $searchfuncs = {google => sub { ... },
                   yahoo => sub { ... },
                   ask => sub { ... },
                   msn => sub { ... }};
               
if ($string =~ /(google|yahoo|ask|msn)\.com\//) {
    &{$searchfuncs{$1}}($string); # for instance
}

BTW I didn't test all this, I'm just writing it in email on the fly. Never
just cut and paste anything without triple checking it.

-- 
Dodger

-----Original Message-----
From: Martin Moss [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 26, 2007 2:30 AM
To: modperl
Subject: regex quickie


I'm looking for a regex which will help me do this..

$string = 'google.com/?q=test';

$pattern_match = 'google|yahoo|msn';

What I would like to do is test if $string contains
one of the patterns in the pattern match and then
carry out a function based upon which pattern is
matched...

e.g.

if ($string =~ /$pattern_match/i)
{
   my $matched_pattern = ####???? ($_?)


}


Any ideas?

sorry for being slightly not mod perl specific...


      ___________________________________________________________ 
Yahoo! Mail is the world's favourite email. Don't settle for less, sign up
for
your free account today
http://uk.rd.yahoo.com/evt=44106/*http://uk.docs.yahoo.com/mail/winter07.htm
l 

Reply via email to