in reply to -c

I think what you want is to eval the entire file right? I'm supposing that you're trying to catch bad script automagically from another script. This is what I've tested:

Consider you have a file called testee.pl with the following code:
#!/usr/bin/perl sub Foo { print "foo\n"; } Bar(); 1;
And that you have your tester file called tester.pl:
#!/usr/bin/perl use strict; eval { require 'testee.pl'; }; if ($@) { warn(); } print "\nDone!\n";
And your result when running tester.pl is:
20:54:50.70@admin:> perl tester.pl Undefined subroutine &main::Bar called at testee.pl line 7. ...caught at tester.pl line 9. Done! 20:54:56.11@admin:>
The only problem I see with this method is that you're testee.pl must return a true statement (hence the 1; at the end). But other than that it seems to do what you want!

UPDATED:

The above doesn't work. Adam has pointed out that the code cannot be executed. It this case, the eval would make everything a big mess...


#!/home/bbq/bin/perl
# Trust no1!

Replies are listed 'Best First'.
RE: Re: -c
by Adam (Vicar) on May 09, 2000 at 04:12 UTC
    Yeah, I suppose I should have made that more clear.
    The scripts can not be run on the developer's machines, for a wide variety of reasons. We catch the error later during tests of the product, but we aught to be able to catch simple errors earlier then that.

    Hey vroom, why can't I 'maintain' that post? I would have liked to just added a clarifier at the end there. Oh well.