in reply to Syntax Error Checking

Why not just send the code straight to "perl -cw" itself?
sub test_code { my $code_to_check = shift; my $pid = open(PERL, "|-"); if (!$pid) { die "fork: $!" unless defined $pid; exec("/usr/bin/perl", "-cw") or die "/usr/bin/perl: $!"; } print PERL $code_to_check; close(PERL); return !$?; # $? == 0 means compile succeeded }
You may want to close STDIN/STDERR to handle any output the forked Perl process gives, and just rely on the exit status, or use open2/open3 if you want to capture the compilation messages Perl gives you.

Replies are listed 'Best First'.
Re (tilly) 2: Syntax Error Checking
by tilly (Archbishop) on Jan 01, 2001 at 22:01 UTC
    perl -cwe 'BEGIN{print "Hello world\n"}'
    Any more questions? :-)