in reply to eval question

my %op_table = ( le => sub { $_[0] <= $_[1] }, ge => sub { $_[0] >= $_[1] }, # etc. ); exists $op_table{ $op } or die "The operator '$op' does not exist.\n"; if ( $op_table{ $op }->( $a, $b ) ) { do something } else { do something else }

Replies are listed 'Best First'.
Re^2: eval question
by rhymejerky (Beadle) on Jan 06, 2011 at 21:21 UTC
    I ended up implementing it using your hash. I was thinking about doing eval and string comparison, but this would not work for cases like comparing 5 le 14. Also, not using eval save me from firing another process

      String eval doesn't launch another process. It merely runs the compiler again.