Dan Muey wrote:
Howdy all:

I'm trying to figure out the best way to test a string agains a list of regexs like so:

my @regex = qw(qr(joe$) qr(^mama) qr([abc]));
        
 if($string does not match any of the regexs in @regex) { .... }
So basically
        if($string !~ [EMAIL PROTECTED]) { ... }

I suppose I could do a for() and set a value accordingly and then test against that in 
my if() statement.
I just figured theres a better way to do it than my initial idea.
        my $matches;
        for(@regex) { if($string =~ m/$_/) { $itmatches++; } }
        if(!$itmatches) { .... }

I could always just do

if($string !~ m/joe$|^mama|[abc]/) { .... }

Just waondering if theres a way to use an actual array in the if statement


Well there is always 'grep' or 'map'....


perldoc -f grep

Remember that grep can take a block rather than a simple expression, but then you are really just talking about a special for loop....

if (grep { $string =~ /$_/ } @regex) {
}

Or something similar...

http://danconia.org


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to