Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: eval question

by jwkrahn (Abbot)
on Jan 06, 2011 at 20:08 UTC ( [id://880927]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found