You can get more elaborate if you like, writing your own warning handler to capture them instead of printing them. It's late and I shouldn't be posting.my $goodcode = <<'CODE'; print "Hello, how are you?\n" CODE my $badcode = <<'CODE'; pront "Hello, how are you\n?' CODE { no strict; local $^W = 0; eval "sub {\n$goodcode\n}"; } print "Goodcode error: $@\n" if $@; { no strict; local $^W = 0; eval "sub {\n$badcode\n}"; } print "Badcode error: $@\n" if $@;
Oh, and the newlines are in there in case you have comments somewhere in your code string. I did once, and it commented out the ending brace of the sub. Beware.
Update: If you want to suppress or log warnings, you can get rid of the 'no strict' and 'local' lines, and use a variant of this instead: local $SIG{__WARN__} = sub {};
It'll create and throw away a new anonymous sub (unless eval() checks for void context -- I dunno), but it'll do the compile-but-not-execute waltz.
In reply to Re: Syntax Error Checking
by chromatic
in thread Syntax Error Checking
by madhatter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |