Bah, if you have to use a hash anyway, eval doesn't help any.
my %perlop = ( lte => sub { $_[0] <= $_[1] }, gte => sub { $_[0] >= $_[1] }, # ... ); my $r = $perlop{$op}->($a, $b);
(Oops, seems I had the page opened a while without realising it, and others have already answered this since then.)
In reply to Re: eval question
by ikegami
in thread eval question
by rhymejerky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |