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

Should you then, for the same reason, undef your scalars, and empty your arrays and hashes when you are done, so your maintainer (if there is a maintainer...) knows you are done? Besides, if the maintainer doesn't understand that going out of scope means you are done with it, wouldn't you have bigger problems than not having an explicite close?

Abigail

  • Comment on Re: problems returning from recursive subroutine

Replies are listed 'Best First'.
Re4: problems returning from recursive subroutine
by dragonchild (Archbishop) on Apr 18, 2003 at 15:07 UTC
    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.

      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.
      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.