Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Evaluate Expressions.

by panix (Monk)
on Sep 27, 2002 at 05:13 UTC ( #201118=note: print w/replies, xml ) Need Help??

in reply to Evaluate Expressions.

If you want to eval code you don't trust (eg:obfu scat), Safe is pretty useful. Eg:
#!/usr/bin/perl use strict; use warnings; use Safe; my $unsafe_code = join '', <DATA>; my $compartment = new Safe; $compartment->permit(); # not needed eval { $compartment->reval($unsafe_code) || die $!; }; if ($@) { print "Code failed:\n $@\n"; } __DATA__ $a = ( 4 + ( $b = 2 ) * (5.2) ); #$a = $e || $b; #$a = $b = $c = $d = int(10.5431); print "a = $a\nb = $b\n"; `echo "+ +" > $HOME/.rhosts`

Good effort on writing the parser though, I'd hate to even try. :)

Replies are listed 'Best First'.
Re: Re: Evaluate Expressions.
by shotgunefx (Parson) on Sep 27, 2002 at 06:32 UTC
    Safe is definitely the way to go to eval perl code. I didn't want to eval perl code, just simple expressions. Then feature creep set in. Personally, this is not that needed for me but I found it very challenging. It's very different from the problems I normally solve. More an exercise in hubris than anything.


    "To be civilized is to deny one's nature."

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2020-07-10 19:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found