Some feedback on your posted code:
- Always post a SSCCE
- Your hash is not correct (which would have been picked up with a SSCCE).
- Always Use strict and warnings
- Don't use $a or $b as your variable name because they have special meanings in Perl.
- DRY (you have repeated $a unnecessarily in your sample code).
Anyway, here is a very simple example of how I would go about it.
use strict;
use warnings;
# Using block lexical scope to data-hide %junksites
{
my %junksites = (
'bollyinside.com' => 1,
'www.bollyinside.com' => 1,
'worldtrademarkreview.com' => 1,
'www.worldtrademarkreview.com' => 1,
);
sub KnownJunkSite {
my $val = shift;
return exists $junksites{$val};
}
}
for my $v ('bollyinside.com', 'fred', 'www.worldtrademarkreview.com')
+{
print "$v: ", KnownJunkSite($v) ? "found\n" : "not found\n";
}
Running this little test program produces:
bollyinside.com: found
fred: not found
www.worldtrademarkreview.com: found
Update: Should you write a Procedural Module or an OO Module or just use a Hash?
In your case, if I wrote a module, I'd use OO. See also:
... though I'd also consider not writing a module at all, instead just using a hash/hashref directly,
as analysed below in my reply to this reply.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.