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

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"; }