Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^5: How to set relational operators to variables to be used by program

by jethro (Monsignor)
on Jul 23, 2012 at 12:23 UTC ( #983163=note: print w/replies, xml ) Need Help??

in reply to Re^4: How to set relational operators to variables to be used by program
in thread How to set relational operators to variables to be used by program

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}) { ...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983163]
[Eily]: I still don't understand how the Turkish AA fit into the German+Czech joke though :P
[LanX]: new Firefox + cb sidebar do random auto expand on submit
[LanX]: probably need to start pm discussion
[LanX]: they have a constitutional referendum in turkey, kind of "do you want a dictator" and everybody opting no gets problems ...
[Corion]: LanX: Random Auto Expand?
[Corion]: LanX: Well, everybody opting "yes" will also get problems. The question is more like "Do you want problems now or problems later?"
[LanX]: and the AA had posters with a big say NO with a small "to alcohol"
[ambrus]: LanX: is it the kind of free and secret vote where there's only one box you can check?

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-03-27 12:16 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.