Is it possible to do $r = eval("$a $op $b")
In principle yes, if you map the operators 'le', 'ge' etc. to the corresponding Perl equivalents — e.g. using a hash.
my %perlop = ( le => '<=', ge => '>=', #... ); my $r = eval "$a $perlop{$op} $b";
(But as always with string eval, be careful what you interpolate when the data ($a, $b here) doesn't come from trusted sources...)
In reply to Re: eval question
by Anonyrnous Monk
in thread eval question
by rhymejerky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |