sub new() { my $class = shift; my $self = {}; $self->{'database'} = "dbi:Sybase:database=$config{'DB_NAME'};server=$config{'DB_SERVER'};hostname=$config{'DB_HOST'};port=$config{'DB_PORT'}"; $self->{'username'} = $config{'DB_USERNAME'}; $self->{'password'} = $config{'DB_PASSWORD'}; bless ( $self , $class ); $self->{'dbh'} = $self->connect(); return $self; } sub DESTROY { my $self = shift; if ( $self->{'dbh'} ) { $self->close(); } } sub connect() { my $self = shift; my $dbh = DBI->connect( $self->{'database'}, $self->{'username'}, $self->{'password'} ); if ( !defined( $dbh ) ) { ... } else { return $dbh; } } sub close() { my $self = shift; my $dbh = shift || $self->{'dbh'}; unless ( $dbh->disconnect() ) { warn "DB disconnect failed: \$DBI::err=$DBI::err, \$DBI::errstr=$DBI::errstr"; } }