Is it possible to do $r = eval("$a $op $b") where $r = 1 because 3 is lte 4? Reason I want to do that is because I have I have some operators pass in, in the form of 'le', 'gt', 'eq'. Currently, I do a if statement for each operator like$a = 3; $b = 4; $op = 'le';
Just want to see if there is a cleaver way to consolidate all those if-else statement into 1 TIAif ($op eq 'le') { if ($a <= $b) { do something } else { do something else } } elsif ($op eq 'ge') if ($a >= $b) { do something } else { do something else } } elsif ....
In reply to eval question by rhymejerky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |