in reply to Multiple Test Regex Does not work the way I expect

You have provided your variables as stringified hash keys as well as test variables and then you're testing their existence against hash values, but $hash{'s'} and $hash{'p1'} values are "empty" still the tests results are not consistent, condsider:
if ( $s =~ $$hash{ "s" }) { print "\t1 ok\n";}else { print "\t1 NOK\n"; if ($d =~ $$hash{ "p1" }){ print "\t2 ok\n";}else{ print "\t2 NOK\n";} !
and you get back:
1 ok #is returned even when the hash doesn't have a corresponding valu +e for $s. 3 NOK #this works correct for $p1?
Since you have used strings, you better use the string comparison operator "eq" and not the =~, and I bet you got tired of the excessive concatenation, use ' ' around the hash keys instead of " " and you would've been saved the trouble...
#!/usr/local/bin/perl #title "Multiple Test Regex Does not work the way I expect"; #see the '' around hash keys.. $hash = { "s" => "", "d" => "19.28.18.28", "p1" => "", "p2" => "88" }; $s="192.168.3.79"; $d="19.28.18.28"; $p1="3269"; $p2="88"; print "$s -> $$hash{'s'}\n"; if ( $s eq $$hash{ "s" }) { print "\t1 ok\n"; }else { print "\t1 NOK\n"; } print "$d -> $$hash{'d'}\n"; if ($d eq $$hash{ "d" }){ print "\t2 ok\n"; }else{ print "\t2 NOK\n"; } print "$p1 -> $$hash{'p1'}\n"; if ($p1 eq $$hash{ "p1"}){ print "\t3 ok\n"; }else{ print "\t3 NOK\n"; } print "$p2 -> $$hash{'p2'}\n"; if($p2 eq $$hash{ "p2" }) { print "\t4 ok\n"; }else { print "\t4 NOK\n"; }


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.