in reply to Re^3: Use of 'our' considered harmful
in thread Use of 'our' considered harmful

I don't use our, so I'm not sure if there's some subtlety going on here that I am missing. With that in mind, I fail to see how your sub differs from:

sub whatever_its_called { my ($dbh) = DBI->connect(...); sub do_hit { $dbh->prepare("stuff"); } }

Look ma! no our! That's the whole point.

- another intruder with the mooring of the heat of the Perl

Replies are listed 'Best First'.
Re^5: Use of 'our' considered harmful
by ikegami (Patriarch) on Sep 24, 2004 at 15:06 UTC

    Actually, your code closes the $dbh before you ever execute the query! Where as the our version doesn't. With the our version, the user can use $dbh in other functions, because $dbh is a global.

    I'm not saying our is required to do this -- it isn't -- I'm just saying you broke the program by blindly switching to my.

      closes $dbh??
        I think he meant, "Closes over an environment with a specific copy of $dbh." And "Closes over" here refers to the process of creating a closure.

        He didn't mean that you're closing the database handle.

Re^5: Use of 'our' considered harmful
by tilly (Archbishop) on Sep 24, 2004 at 15:31 UTC
    You don't want to try to define a named sub inside of another named sub! You can get away with it if you only use global variables, but you never want to do it with lexicals.

    You have just triggered the infamous puzzling, "variable will not stay shared" warning. See Re (tilly) 9: Why are closures cool? which tries to explain what Perl is trying to warn you about and why there is no good resolution to the problem.