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!
In reply to Re: -c
by BBQ
in thread -c
by Adam
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.