in reply to Emulating -c within perl

Call perl with backticks for each file (as in `perl -c $filename`;). eval isn't meant as a code checking system--it's for trapping errors and running dynamically-generated code.

Also, be warned that any file with a BEGIN block will still have code executed under -c, so don't run this on any ol' code you find.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: Emulating -c within perl
by liz (Monsignor) on Sep 12, 2003 at 15:16 UTC
    You probably want to exchange "perl" with "$^X" inside the backticks to ensure you're using the same Perl as you're currently running with. Unless of course you want to check the behaviour in another version of Perl. ;-)

    Liz

Re: Re: Emulating -c within perl
by ViceRaid (Chaplain) on Sep 12, 2003 at 15:24 UTC

    Thanks. After running `perl -c foo.pl`, how do I check what the result was? If I was running an eval, I'd check $@, but the return value from `` is just a string, so I can't check that directly.

    Update: aah, looks like I should be using $?. Also, thanks for the pointer, liz.