in reply to Re^2: What does 'last OP;' do?
in thread What does 'last OP;' do?

I would go further, and make a single array or hash containing all of %NUM_OPS and %STR_OPS. For example:

BEGIN { $OPS{'num'}{$_} = eval "sub { \$_[0] $_ \$_[1] }" foreach (qw(< <= != >= > ==)); $OPS{'str'}{$_} = eval "sub { \$_[0] $_ \$_[1] }" foreach (qw(lt le ne ge gt eq)); } # ... and later ... $v = ${$pairs{$ca}}[0]; my $op_type = $types{$ca} ? 'num' : 'str'; my $op = $OPS{$op_type}{$co}; die("Undefined operation $co.\n") unless $op; $r &= $op->($v, $cv);

It would be even better if you could alter the code which sets up %types, so that instead of true and false values, it could store the strings we need: 'num' or 'str'.

--
TTTATCGGTCGTTATATAGATGTTTGCA