in reply to Re^4: Hash versus chain of elsifs
in thread Hash versus chain of elsifs
Some feedback on your posted 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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Hash versus chain of elsifs
by eyepopslikeamosquito (Archbishop) on Nov 23, 2021 at 11:34 UTC |