teabag has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks, lend me your ears...
Teabag
I'm sure there's more than one way, but /me just needs one anyway - Teabag
I'm trying to write an urlgrabber and I thought it would be nice to include a sort of blacklisting system with it. Now the code for the grabbing/webscraping works perfectly. But I'm having problems with the blacklisting system.
I have 2 arrays. One (@sites) contains the grabbed urls, the other one (@blacklist) contains the blacklisted keywords. Now the code I came up with does "kinda" spot the blacklisted urls, but is clumsy, slow, inefficient and has to be filtered.
Could anyone point out an easier (and faster) way?
#!/usr/bin/perl # example blacklisting @sites = ( "http://www.rtfm.com", "http://www.alottatax.com", "http://www.kingdom.com/cgi-bin/script.pl" ); @blacklist = ( "cgi", "blabla", "testme" ); foreach $site (@sites) { &blacklist(); } sub blacklist { foreach $blacklist (@blacklist) { if ( $site =~ m/$blacklist/gi ) { print "$site blacklisted - $blacklist\n"; } else { print "$site ok\n"; } } }
Teabag
I'm sure there's more than one way, but /me just needs one anyway - Teabag
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Filtering one array using another array
by Abigail-II (Bishop) on Sep 04, 2003 at 13:27 UTC | |
by teabag (Pilgrim) on Sep 04, 2003 at 13:34 UTC | |
Re: Filtering one array using another array
by broquaint (Abbot) on Sep 04, 2003 at 13:33 UTC | |
by teabag (Pilgrim) on Sep 04, 2003 at 13:40 UTC | |
Re: Filtering one array using another array
by Kimi_1973 (Initiate) on Sep 04, 2003 at 13:40 UTC | |
by teabag (Pilgrim) on Sep 04, 2003 at 13:53 UTC | |
by Kimi_1973 (Initiate) on Sep 04, 2003 at 13:50 UTC | |
Re: Filtering one array using another array
by gjb (Vicar) on Sep 04, 2003 at 13:24 UTC | |
by Abigail-II (Bishop) on Sep 04, 2003 at 13:31 UTC |
Back to
Seekers of Perl Wisdom