In addition to kennethk's comment above, I would also recommend that you add a validity check to check(), something like (untested):
(Instead of returning an oddball message, you could die at that point.)sub check { my $ck = shift; my %message= ( 'y345' => " Close ", '1223dx' => " Open ", '88888' => " Gone ", 'acb2' => " Available ", '1114' => " Exit ", ); return 'unknown or missing check value' unless defined($ck) and exists $message{$ck}; return $message{$ck}; }
Also note that in the OPed code, main() is called without arguments. As such, in the statement
my $data = shift || return;
the value returned by shift will always be undefined, hence false, and main() will always immediately return.
Give a man a fish: <%-{-{-{-<
In reply to Re: Return a hash value based on its key
by AnomalousMonk
in thread Return a hash value based on its key
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |