rhymejerky has asked for the wisdom of the Perl Monks concerning the following question:
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 ....
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: eval question (avoid string eval References)
by eyepopslikeamosquito (Archbishop) on Jan 06, 2011 at 20:17 UTC | |
Re: eval question
by jwkrahn (Abbot) on Jan 06, 2011 at 20:08 UTC | |
by rhymejerky (Beadle) on Jan 06, 2011 at 21:21 UTC | |
by chromatic (Archbishop) on Jan 07, 2011 at 01:02 UTC | |
Re: eval question
by ikegami (Patriarch) on Jan 06, 2011 at 20:22 UTC | |
Re: eval question
by Anonyrnous Monk (Hermit) on Jan 06, 2011 at 19:49 UTC | |
by moritz (Cardinal) on Jan 06, 2011 at 19:59 UTC | |
Re: eval question
by locked_user sundialsvc4 (Abbot) on Jan 07, 2011 at 01:53 UTC | |
by rhymejerky (Beadle) on Jan 07, 2011 at 02:37 UTC |