Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by ariels (Curate)
on May 07, 2002 at 07:48 UTC ( [id://164556]=note: print w/replies, xml ) Need Help??


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

... and it still executes those pesky BEGIN blocks.

Some days you just have to love Perl's DWIDM features.

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

Replies are listed 'Best First'.
Re: Re: Re: Re: Can you check the syntax of a eval() before executing it?
by Dog and Pony (Priest) on May 07, 2002 at 09:09 UTC
    That is true. I can see no good way to avoid that, either. Something like:
    my $coderef = eval "BEGIN{goto skip;}sub { $code } BEGIN{skip: print ' +Skipped!'}";
    will not work. Not that I am sure it would be good if it did either... return and exit both also yield unsatisfying results, not surprisingly.

    However, if you are afraid that someone might execute harmful code, then that is a whole nother issue, and you will not be protected just by verifying the syntax (which was what I addressed). However, if you use Safe, and do like this:

    use Safe; my $compartment = new Safe; my $coderef = $compartment->reval("sub{$code}") or die "$@"; $coderef->(); # execute the code
    The Safe compartment will stop whatever you decide is harmful code even in BEGIN blocks.

    If the issue rather is that it is annoying that code will become executed, well then some kind of filter might be in place I guess. For instance, for nearly all applications I could think of (short of a perl editor of course) disallowing the word "BEGIN" in the input (possibly in special cases, like followed by braces) would not be a big problem, would it?

    It is definetely something to be aware of though. Good call. :)


    You have moved into a dark place.
    It is pitch black. You are likely to be eaten by a grue.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 03:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found