Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Can you check the syntax of a eval() before executing it?

by erikharrison (Deacon)
on May 06, 2002 at 20:20 UTC ( #164435=note: print w/ replies, xml ) Need Help??


in reply to Can you check the syntax of a eval() before executing it?

There isn't a really good way to do this within Perl . . . however, if you absolutely must double check, you can execute perl from within your program on a temp file containing the source, using the -c switch. But you don't want to do that.

Cheers,
Erik

Update: Chmrr makes a good point about BEGIN blocks . . . see below


Comment on Re: Can you check the syntax of a eval() before executing it?
Re: Re: Can you check the syntax of a eval() before executing it?
by Chmrr (Vicar) on May 06, 2002 at 20:28 UTC

    This has been discussed previously here at the monastery, but I can't seem to find where. The general consensus is that it is not possible. The perl -c trick will not prevent code from being executed; see the following, for example:

    [chmrr@supox chmrr]$ perl -c BEGIN {print "Nope!"} Nope!- syntax OK

    perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2015-07-07 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (86 votes), past polls