in reply to syntax check from within perl
The eval function with quoted argument traps compile errors. You can examine the error messages in the perlvar $@. No other special magic is needed. This is not true of eval BLOCK.
Update: <shrug>If you want to avoid runtime on your eval string, just wrap it in a conditional:
I used $^C, the compile-time flag, for cli convenience, but some $debug would do as well.$ $ perl -Mstrict -e'$_="printed\n";my$foo=q(print);eval"if(\$^C){$foo}" +;print $@ if $@' -- #no compile or run error $ $ perl -Mstrict -e'$_="printed\n";my$foo=q(quux);eval"if(\$^C){$foo}"; +print $@ if $@' -- # compile error Bareword "quux" not allowed while "strict subs" in use at (eval 1) lin +e 1. $ $ perl -Mstrict -e'$_="printed\n";my$foo=q(&quux);eval"if(\$^C){$foo}" +;print $@ if $@' -- # runtime error $ $ perl -Mstrict -e '$_="printed\n";my$foo=q(print);eval"$foo";print $@ + if $@' -- # conditional removed, no errors printed $
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: syntax check from within perl
by Anonymous Monk on Mar 02, 2002 at 06:23 UTC | |
by bbfu (Curate) on Mar 02, 2002 at 07:23 UTC | |
by merlyn (Sage) on Mar 02, 2002 at 08:00 UTC | |
by Anonymous Monk on Mar 02, 2002 at 07:30 UTC | |
by bbfu (Curate) on Mar 02, 2002 at 07:35 UTC |