Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Returning data from an eval

by holli (Monsignor)
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-10-17 02:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...














    Results (90 votes). Check out past polls.

    Notices?