in reply to Re: 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?
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.my $coderef = eval "BEGIN{goto skip;}sub { $code } BEGIN{skip: print ' +Skipped!'}";
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:
The Safe compartment will stop whatever you decide is harmful code even in BEGIN blocks.use Safe; my $compartment = new Safe; my $coderef = $compartment->reval("sub{$code}") or die "$@"; $coderef->(); # execute the code
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. :)
|
|---|