in reply to Re: DBI detector?
in thread DBI detector?

Error wise I get
Can't locate DBI.pm in @INC (@INC contains: .....)  at DBIDetector.pl line 14

jcpunk
all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

Replies are listed 'Best First'.
Re^3: DBI detector?
by ikegami (Patriarch) on Apr 03, 2006 at 20:31 UTC
    Hum, there goes my theory. Could you show us your script, especially what's at and around line 14?
      Sure... here it is
      #!/usr/bin/perl use strict; my $use_dbi = 1; eval("use DBI;"); $use_dbi = 0 if (not($@)); print `uname -n`; print `prtconf |grep Mem` if (`uname` eq 'SunOS'); print `cat /proc/meminfo` if (`uname` eq 'Linux'); if ($use_dbi) { use DBI; print "Hurray!!\n"; } else { print "NO DBI\n"; }
      ... for what it is worth...

      Thanks for the interest.


      jcpunk
      all code is tested, and doesn't work so there :p (varient on common PM sig for my own ammusment)

        Oops, I hadn't noticed you had use DBI; inside the if.

        use ...; occurs at *compile* time and unconditionally. In other words, your code is identical to

        #!/usr/bin/perl use strict; use DBI; my $use_dbi = 1; eval("use DBI;"); $use_dbi = 0 if (not($@)); print `uname -n`; print `prtconf |grep Mem` if (`uname` eq 'SunOS'); print `cat /proc/meminfo` if (`uname` eq 'Linux'); if ($use_dbi) { print "Hurray!!\n"; } else { print "NO DBI\n"; }

        It's quite easy to fix: Remove the use DBI; since it's already done in the eval EXPR. As you can see in my earlier fixed code, I removed that line (apparently without realising it!).

        Here's the fix with a couple of small cleanups:

        #!/usr/bin/perl use strict; use warnings; # Always good to have. print `uname -n`; my $uname = `uname`; # Only run "uname" once. print `prtconf |grep Mem` if ($uname eq 'SunOS'); print `cat /proc/meminfo` if ($uname eq 'Linux'); my $use_dbi = eval("use DBI; 1"); # More concise than checking $@. if ($use_dbi) { print "Hurray!!\n"; } else { print "NO DBI\n"; }