in reply to regex match in array

( {map { $_ => 1 } @myTerms}->{"term"}
That's a hard way to do it. Try this.
grep $_ eq "term", @myTerms
Then doing the regex comes out trivially:
grep /TE(.)M/i, @myTerms

Dave.

Replies are listed 'Best First'.
Re: Re: regex match in array
by rsiedl (Friar) on May 27, 2004 at 13:24 UTC
    Cool, thanks.

    Thats just a bit easier :)
Re: Re: regex match in array
by rsiedl (Friar) on May 27, 2004 at 14:20 UTC
    Not sure how I should do this but i have a follow-up question. Should it be posted as a new node or in reply...?
    Anyway this time I'll do it as a reply and if it is the wrong thing just let me know.

    The question is:
    How can i get the match to match at least a whole item from the array?
    i.e.
    #!/usr/bin/perl use strict; use warnings; my @myTerms = ( 'blah foo', 'test' ); my $term = "blah"; if ( grep /\Q$term\E/, @myTerms) { print "$term does match\n"; } # end-if exit;
    will match, but i would only like it to match if the _term_ is /^blah foo(.*)/
    Could you help me out?
    Cheers,
    Reagen