Eval is probably the way to go with this, as others have shown. For extra style points, make it into an anonymous sub so as to ensure that the overhead of eval only happens once:
sub makeop { my $op = shift; return eval 'sub {$_[0] '.$op.' $_[1]}'; } my $x = 42; my $y = 50; my $op = makeop(">="); if ($op->($x, $y)) { ... }
perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'
In reply to Re: Dynamic operators
by Chmrr
in thread Dynamic operators
by Preceptor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |