At 01:37 AM 7/14/02 +0800, Connie Chan wrote:
> > As noted you should do the require in an eval block
> > so that you can gracefully manage the "oopsies"...
>
>I don't really know how to, so a stupid way to solve this problem :
>
>my $libPath = 'C:/perl/lib/myLib/';
>my $script = 'ScriptA.pl';
>
>if (-e $libPath.$script) { require ($libPath.$script) }
>else { print "Fail to load ".$script; exit(0) }
Not bad, but:
(1) Doesn't handle the possibility that the file might not be readable,
or might not parse;
(2) If you can't read it you exit the program with an error anyway, so
why not let Perl do it for you? :-)
I'd probably put in
use lib qw(C:/perl/lib/myLib);
given that that looks like a place to store library files
and then
require 'ScriptA.pl';
and let Perl die for me if it has a problem. Catching the die is
usually only pointful if you have a way to proceed, e.g.:
eval {
require 'ScriptA.pl';
}
or eval {
require 'ScriptB.pl';
}
or die "I give up";
It is extremely rare for me to have a good reason to do this...
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]