package DBconnector; my $singleton; sub new { my $class = shift; $singleton ||= bless {}, $class; } sub connect { my $self = shift; if (exists $self->{dbh}) { $self->{dbh}; } else { my $connection = "dbi:mysql:host=$self->{host} \ dbname=$self->{name}"; $self->{dbh} = DBI->connect($connection, \ $self->{user},$self->{password}); } }