You asked me per /msg, why adding "\" in front of your variables is still not working.
Well, generally it is. See this short test script:
#!/usr/bin/perl
use strict;
use warnings;
my $x="a";
my %hash;
$hash{"a"}= "ding";
$hash{"b"}= "junk";
$hash{"c"}= "ding";
for my $right ("a","b","c") {
if (eval "\$hash{\$x} eq \$hash{\$right}") {
print "yes\n";
}
else {
if ($@ ne "") { print "ERROR: $@\n"; }
else { print "no\n";}
}
}
try to remove the "\" inside the eval and you will see error messages instead
If your code is not working, something else must be wrong. Maybe you have a typo or your variables are constructed differently than you think. Check variable values, i.e. print them out, check that they don't have \n at the end... Check if there are errors, and if yes, try to read them carefully
To your question about checking the values, see BrowserUKs post, his script does check. Simpler methods are for example:
#regex way
if ($op=~m/^(==|eq|<|>)$/) {
...
#hash way
my %allowedops=( '=='=>1 , 'eq'=>1 , '>'=>1 , '<'=>1 );
if ($allowedops{$op}) {
...
|