http://www.perlmonks.org?node_id=480127


in reply to Returning data from an eval

First, in your rule you are using "=" to do a string comparison. Don't do that. use eq.

I have a similar program which reads rules from a xml-file and applies them to a bunch of data. I do compile those rules into anonymous subroutines and call them later on. That is far faster then evaling the same code over and over again. Like so:
# @rules read from file or somewhere else my @rules = ( 'return( "A", "Cat A" ) if $_[0] < 75000 and $_[1] eq "ICE";', #... ); # convert rules to anon subs @rules = map { eval "\$_ = sub { $_ }"; } @rules; for ( @rules ) { print join ",", &$_(20000, "ICE"); #A, Cat A }


holli, /regexed monk/