in reply to Re^2: 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
The usual warning: If you use eval, you have to make sure that either no evildoer can put any code into the file where the opcodes are stored or that you check the values with regexes so that only acceptable ops get through
And something else: If you use $hash{$filter[0]->[0]} inside the eval string, it is substituted with its value as well. This is fine as long as you want to compare numbers, because (10 < 20) is a valid comparision expression in perl, but if you want to also compare strings, for example "blue" and "green", then the eval will fail because (blue lt green) is not a valid expression, it should be ("blue" lt "green"). Solution: Escape the operands like this: \$hash{\$filter[0]->[0]}
And your example filter 3 (for column b) is wrong, '=' is assignement, '==' is equality (which would suggest that a regex to check for correct relationships/operators might not be a bad idea anyway)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: How to set relational operators to variables to be used by program
by dkhalfe (Acolyte) on Jul 19, 2012 at 18:04 UTC | |
by jethro (Monsignor) on Jul 23, 2012 at 12:23 UTC |