Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Use of 'our' considered harmful

by tantarbobus (Hermit)
on Sep 24, 2004 at 09:46 UTC ( #393432=note: print w/replies, xml ) Need Help??


in reply to Use of 'our' considered harmful

You would probably be better off using  use vars qw// instead of my, since it is more like our. And as for a real world situation, how about a closure where you want to use a var declared outside of the closure, but without "making a copy of the var".

Replies are listed 'Best First'.
Re^2: Use of 'our' considered harmful
by grinder (Bishop) on Sep 24, 2004 at 10:37 UTC
    how about a closure where you want to use a var declared outside of the closure

    Well, by definition, a closure does operate on variables outside itself... that's the whole point.

    As for a closure that is based on a global variable (lexical or otherwise), I can only ask "Why would you want to do a thing like that?" If the variable is global, it sort of defeats the purpose of wrapping it up in a closure. (Otherwise you would just use local).

    So yes, you could do so, but I don't think it qualifies as a Real World Example™ as per the OP. I think anything you could come up with could be wrapped up in a sub and use lexical mys, and I think it would be better that way.

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

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

        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

        But surely my would be more appropriate here - $dbh is still a global variable, it is only the effect of our that is lexical.

        /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://393432]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2019-10-18 08:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?