As you asked about syntax checking and not security, I'll assume that you have the security aspect covered.
There's probably a gotcha I haven't thought about, but if you issue a return immediately at the front of the code to be checked, that will prevent any furthur code being executed--except of course for BEGIN{...} and END{...} blocks, see later--but still allow syntax checking to occur.
I believe (quite possibly wrongly), that if you remove any newlines, that BEGIN and END blocks can be match with a regex of /(?:BEGIN|END)\s*\{/ Using this to prefix them with something like sub syntax_check_ will prevent them from being run, but will allow them to also be syntax checked.
#! perl -slw use strict; while(<DATA>) { chomp; my $code = $_; tr/\n//d; s[((?:BEGIN|END)\s*{)][sub syntax_check_$1]g; eval 'return;' . $_; print "'$code' \n\t: ", $@ ? "Fails with\n$@" : 'Passes syntax che +ck'; } __END__ INIT { print '*** GOTCHA!!! ***'; } BEGIN{ print '*** GOTCHA!!! ***'; } END { print '*** GOTCHA!!! ***'; } my $a = 1; my $a = cool; my $
Whether this level of syntax checking is enough to satisfy your requirements only you will know.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
In reply to Re: run-time syntax checking
by BrowserUk
in thread run-time syntax checking
by Pardus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |