优化了下程序,让它更加简单。。
package TDmodule; use DBI; sub new{ $self={}; $self->{select_db}=undef; bless $self; return $self; } sub connect_db{ my $self=shift; if(@_){ $self->{'connect_db'}=DBI->connect("DBI:mysql:database=@_[0];host=@_[1]","@_[2]","@_[3]") or die "No:$! "; } return $self->{'connect_db'}; } sub select_db{ my $self=shift; if(@_){ my $select=@_[0]->prepare(@_[1]); $select->execute(); $self{select_db}=$select; } return $self{select_db}; } 1;