in reply to run-time syntax checking
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: run-time syntax checking
by ihb (Deacon) on Feb 01, 2003 at 16:57 UTC | |
by BrowserUk (Patriarch) on Feb 01, 2003 at 20:44 UTC | |
by ihb (Deacon) on Feb 02, 2003 at 01:28 UTC | |
by BrowserUk (Patriarch) on Feb 02, 2003 at 04:33 UTC | |
by ihb (Deacon) on Feb 28, 2003 at 23:43 UTC |