This works:
package Syntax; our $VERSION = '1.00'; use B qw(minus_c save_BEGINs); sub import { eval q[ BEGIN { minus_c; save_BEGINs; close STDERR; open (STDERR, ">", \$Syntax::stderr); } ]; die $@ if $@; } 1;
And invoke like this:
perl -MSyntax -e '1+' # gives non-zero return code perl -MSyntax -e '1+2' # gives zero return code perl -MSyntax my_program.pl
When there is an error, that is captured in $Syntax::stderr above. The module could be extended to allow one to pass in a file name to write when there is an error.
A still open question is to remove the "perl" invocation and have available $Syntax::stderr. do looks close, but is still a ways off.
I may try to fill out the above and make a perl Module out of it.
In reply to Re^6: How to do perl -c inside perl?
by rockyb
in thread How to do perl -c inside perl?
by rockyb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |