optional 'require'

Jacqui Caren jacqui.caren at ntlworld.com
Wed Dec 21 16:11:38 GMT 2005


Dirk Koopman wrote:
> For some reason (probably due to old age and lack of brain brought on by
> excess alcohol) I am having difficulty determining, in an optional
> non-stopping way, whether DBI (and at least DBD::SQLite) is installed on
> the machine.
> 
> I have an app which traditionally has used flat files and DB_File to
> store the data that it has acquired. I want to allow seamless upgrade to
> a SQL based version. 
> 
> Therefore I want to test for the presence of DBI and at least one true
> SQL engine. However it is vital that this test is non destructive and
> the app carries on as normal if these are not available.
> 
> I have tried various styles of: eval { require DBI; }; and eval "require
> DBI"; so far without adequate success.

What is the problem with the require?

If you said eval { use ... } I could understand why the eval "fails".

Hint: available_drivers() method after an import.

i.e.
  eval "require DBI";
  unless ($@) {
   import DBI;
   print join(" ",DBI->available_drivers())."\n";
  } else {
   print "No DBI\n";
  }

With two local perls...

jacqui at PAULNJ sendmail]$ /usr/bin/perl b
ExampleP InterBase Sponge mysql
[jacqui at PAULNJ sendmail]$ /usr/local/p584i/bin/perl b
CSV DBM ExampleP File InterBase Pg Proxy Sponge
[jacqui at PAULNJ sendmail]$




More information about the london.pm mailing list