in reply to DBI connect problem

It seems as though your logic is backwards... my $result = defined($dbh); ...so far so good... if (!$result) { ...this is saying if $result is not defined, and this does not correlate with your statements...

you should change if (!$result) { to if (!defined($dbh) ) { giving the following code, which should make more sense

if (!defined($dbh) ) { $errStr .= " [dbh UNDEFINED]".$testStr; $self->log_comment("ERROR: db_connect => ".$errStr); } else { $errStr .= " [dbh DEFINED]".$testStr; }

--
hiseldl

Replies are listed 'Best First'.
Swap branches refactoring
by IlyaM (Parson) on Jul 31, 2002 at 08:02 UTC
    I would refactor code like
    if (!defined($dbh) ) { $errStr .= " [dbh UNDEFINED]".$testStr; $self->log_comment("ERROR: db_connect => ".$errStr); } else { $errStr .= " [dbh DEFINED]".$testStr; }
    into
    if (defined $dbh) { $errStr .= " [dbh DEFINED]".$testStr; } else { $errStr .= " [dbh UNDEFINED]".$testStr; $self->log_comment("ERROR: db_connect => ".$errStr); }
    Idea of this refactoring is that if you have an if/else construct it makes sense to swap branches if it simplifies the condition.

    --
    Ilya Martynov (http://martynov.org/)