On Sep 23, Manish Sapariya said:

In following db functions I am using returned "statement handle "
and afterword just ignoring it and overwrite it with the newly
returned value.

Does this cause memory leak/ or any kind of resouce leak?
Can I reuse statement handle in such a way? If not, what is
cleaner way to do it?

You're doing it in an acceptable manner. One suggestion would be to move the scope of $sth to JUST the foreach loop, though:

   my $sth;
   ...
   foreach $table (@$rTableListRef) {
        $query = "select count(*) from $table";
        $sth = perform_query($query);
      ...
   }

might be better written as

   foreach $table (@$rTableListRef) {
        $query = "select count(*) from $table";
        my $sth = perform_query($query);
      ...
   }

The other thing I've noticed is your use of function prototypes. Don't use them, because they are rarely needed, and your program isn't even actually using them at all. Not to mention this one is written wrong:

sub perform_query($$) {
   my ($query) = @_;
   ...
}

Your prototype SAYS it's getting TWO scalars, but you've only passed one. But this is never noticed because you've called the function *before* Perl has seen its prototype.

Long story short:  don't use prototypes.

--
Jeff "japhy" Pinyan        %  How can we ever be the sold short or
RPI Acacia Brother #734    %  the cheated, we who for every service
http://www.perlmonks.org/  %  have long ago been overpaid?
http://princeton.pm.org/   %    -- Meister Eckhart

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to