in reply to Re: problems returning from recursive subroutine
in thread problems returning from recursive subroutine

I make a distinction between connections to outside processes (like databases and files) and internal things (like variables and the like).

The thing that bit me regarding this (because I always used to work with implicit closes) was prepare_cached(). The following snippet, within a function that's called repeatedly, will not work as expected:

sub oft-used_func { .... if ($do_db_call) { my $sth = $dbh->prepare_cached($sql) || die; $sth->execute(@bind_vars) || die; while ($sth->fetch) { .... } # Use implicit close here # $sth->finish; } .... }
The second time you do that DB statement, using prepare_cached() and not having called finish(), you will have a DBI error. Thus, I explcitly close all external things, but implicitly close all internal things.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: problems returning from recursive subroutine
by Abigail-II (Bishop) on Apr 18, 2003 at 15:33 UTC
    So, you think directories should be closed explicitely, just because you were once bitten by a database module that is not part of the Perl main distribution.

    Interesting. I was once bitten by a cat, therefore everyone should use a space between the array name and its index.

    Abigail

      So that's why you do that...I always wondered:)


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.
Re^6: problems returning from recursive subroutine (dbi handle != dir/file handle)
by Aristotle (Chancellor) on Apr 18, 2003 at 15:19 UTC
    But that's DBI and prepare_cached, not a file or directory handle. Note that file and directory handles are resources Perl can natively deal with, while other handles allocated in an external process are not.

    Makeshifts last the longest.