in reply to Changing a subroutine to a module

The following is wrong since ' ' is true:

my $dbh = shift ||' '; my $sth = shift ||' '; ... $sth->finish() if $sth; $dbh->disconnect() if $dbh;

The above is equivalent to:

my $dbh = shift; my $sth = shift; ... if ($sth) { $sth->finish(); } else { ' '->finish(); # RUNTIME ERROR } if ($sth) { $dbh->disconnect(); } else { ' '->diconnect(); # RUNTIME ERROR }

Why not just do this:

my $dbh = shift; my $sth = shift; ... $sth->finish() if $sth; $dbh->disconnect() if $dbh;