package Mylibrary;
use strict;
use DBI;
my $database="somedb:localhost";
my $username="username";
my $password="password";
sub connect
{
my $dbh = DBI->connect("DBI:mysql:$database",
"$username","$password")
or error_fatal("blah");
return $dbh;
}
sub get_current_vote
{
my ($dbh) = @_;
# if we're not connected (or weren't passed
# a connection), connect
$dbh ||= connect();
my $sth = $dbh->prepare("SELECT current_vote FROM
vote_count;");
$sth->execute() or die $dbh->errstr();
my $current_vote = ($sth->fetchrow_array())[0];
return $current_vote;
}
1;
####
# my funky script
use strict;
use DBI;
use Mylibrary;
# connect to library:
my $dbh = Mylibrary::connect();
# get current vote:
my $current_vote = Mylibrary::get_current_vote($dbh);
####
# my funky script
use strict;
use DBI;
use lib '/path/to/my/library/';
use Mylibrary;