http://qs321.pair.com?node_id=1101118

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I have the same kind of logic in my code, it seems redundant and I am trying to improve it, but I am running out of options. Is there a better way to have all this code in a hash and match against what comes in from the

my $item = $q->param( 'item' ) || '';

Here is the code I am trying to improve:
#!/usr/bin/perl use strict; use warnings; use CGI; use Data::Dumper; my $q = CGI->new(); print $q->header(); my $item = $q->param( 'item' ) || ''; my $change; # Get values if($item=~/test/) { $change = "blue"; }elsif($item=~/dark/){ $change = "black"; }elsif($item=~/white/){ $change = "light"; }elsif($item=~/house/){ $change = "home"; }elsif($item=~/all things/){ $change = "multi"; }elsif($item=~/money/){ $change = "value"; }elsif($item=~/country/){ $change = "USA"; }else{ $change = "neutral"; } print "Final Item = $change";
Thanks for the help!