Search code examples
perlsybasedbiresource-cleanup

Cleanup of statement handlers in DBI perl


I am using DBI perl to connect with Sybase dataserver. My process does the following in loop that runs throughout the day

Till end of day, do {
  $sth = $dbh->prepare
  execute query
  someAnotherPerlFunction()
  someAnotherPerlFunctionOne()
}

someAnotherPerlFunction()
{
   $sth = $dbh->prepare (select)
   execute query
}

someAnotherPerlFunctionOne()
{
   my $sth = undef;
   $sth = $dbh->prepare (update)
   execute query;
   undef $sth;
}

Now, given that this will run throughout the day, what are some of the things that I need to keep in mind in terms of resource cleanup.

Currently, I am doing undef $sth after each function, as shown in someAnotherPerlFunctionOne. Is that necessary?


Solution

  • Perl will clean up for you, but it is a good idea to pass your db handle to the functions instead of recreating it every time and destroying it immediately.