Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: OUR declaration

by Anonymous Monk
on Sep 23, 2006 at 03:16 UTC ( [id://574480]=note: print w/replies, xml ) Need Help??


in reply to Re: OUR declaration
in thread OUR declaration


thanks. that was an excellent article.
let me ask a follow-up question

for the "normal" scenario of one file == one package;
is there ever a case where our (instead of my) is needed?

Replies are listed 'Best First'.
Re^3: OUR declaration
by tilly (Archbishop) on Sep 23, 2006 at 03:26 UTC
    Needed? You need a global variable if you are going to set one with special meaning to Perl, or to an external module. But even then you don't need our to set those globals. (The most common globals that people do this with are @ISA, $VERSION, @EXPORT and @EXPORT_OK.)

    For instance a lot of people tend to write:

    package Foo; use strict; our @ISA = 'Bar'; ...
    instead of
    package Foo; use strict; use vars qw(ISA); @ISA = 'Bar'; ...
    so you can save a line. However you can solve that problem in other ways, for instance:
    package Foo; @ISA = 'Bar'; use strict; ...
    or
    package Foo; use strict; @Foo::ISA = 'Bar'; ...
    or in this case
    package Foo; use strict; use base 'Bar'; ...
    So our is always pretty gratuitous.
Re^3: OUR declaration
by perrin (Chancellor) on Sep 23, 2006 at 04:05 UTC
    If you want a global variable, i.e. one that can be read from other packages and does not go out of scope, then you either spell the whole thing out ($SomePackage::Variable) or use our so you can say ($Variable) within that file.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-25 05:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found