perlquestion
Anonymous Monk
Hi Monks!<br>
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 <br><br>
<code>my $item = $q->param( 'item' ) || '';</code><br><br>
Here is the code I am trying to improve:<br>
<code>
#!/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";
</code>
Thanks for the help!
9