Matthew Ramadanovic wrote:
> Why not just do something like this:
> 
> #!/usr/bin/perl
> eval {
> use DBI;
> };
> if ($@) {
> print "Couldn't use DBI : [EMAIL PROTECTED]";
> } else {
> print "Loaded DBI successfully\n";
> }

Output:
Can't locate DBI.pm in @INC ...

Although this does indeed tell me that DBI is not installed, it doesn't
happen the way you wanted.  "use" happens at compile time so you can't
capture compile errors in [EMAIL PROTECTED]  To check for these at run time, 
you need
to use either require() or eval "".

  if (eval { require DBI }) {
    print "DBI is installed\n";
  }
  if (eval "use DBI") {
    print "DBI is installed\n";
  }

- Philip

Reply via email to