Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Returning data from an eval

by holli (Abbot)
on Aug 02, 2005 at 09:15 UTC ( #480127=note: print w/replies, xml ) Need Help??

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/

Replies are listed 'Best First'.
Re^2: Returning data from an eval
by Tanalis (Curate) on Aug 02, 2005 at 09:42 UTC
    Meh .. dumb typo in the comparison there. Thanks.

    I'd not thought about using anonymous subs - thanks for the tip. It certainly seems to speed things up - I'm doing a fairly large number of iterations over the code.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://480127]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2020-11-25 00:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found