in reply to Filtering one array using another array

How's about
use strict; my @sites = ( "http://www.rtfm.com", "http://www.alottatax.com", "http://www.kingdom.com/cgi-bin/script.pl" ); my $blacklist = join '|', map quotemeta, qw/ cgi blabla testme /; for(@sites) { printf "%s %s\n", $_, $_ =~ /($blacklist)/ ? "blacklisted - $1" : 'ok'; } __output__ http://www.rtfm.com ok http://www.alottatax.com ok http://www.kingdom.com/cgi-bin/script.pl blacklisted - cgi
See. perlre and quotemeta for more info. Also a module that might be of interest - Regex::Presuf.
HTH

_________
broquaint

Replies are listed 'Best First'.
Re: Re: Filtering one array using another array
by teabag (Pilgrim) on Sep 04, 2003 at 13:40 UTC
    Perfect broquaint!
    I understand the very simple regexes, but get lost when they get complicated.

    I'll check out that module you mentioned right away. Sounds very handy.

    Thanks

    Teabag
    Sure there's more than one way, but one just needs one anyway - Teabag