Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Global Variables and Pointer(Reference).

by raaj (Acolyte)
on Apr 10, 2013 at 05:31 UTC ( #1027889=perlquestion: print w/replies, xml ) Need Help??
raaj has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monk, i need the justification for, why we cant avoid the global variables(Packege Variable)and reference in perl while building any of the big Tool. Please help me in this regard.

  • Comment on Global Variables and Pointer(Reference).

Replies are listed 'Best First'.
Re: Global Variables and Pointer(Reference).
by davido (Archbishop) on Apr 10, 2013 at 06:40 UTC

    @ISA is used as a package global. It also happens to be how Perl keeps track of inheritance. Now you may mostly be able to ignore that it's being used, by using the base or parent pragmas, but it's still there if your package inherits from something.

    So if "building any of the big Tool" includes building classes that inherit from other classes, you can't avoid using package globals.

    If you tried using "my @ISA", it just wouldn't work out; the inheritance chain needs to be recorded in the symbol table, not the lexical pad, because that's where Perl will go looking for it.

    Even a module that just exports its functions will usually rely on Exporter by saying something like, "our @ISA = qw( Exporter );... and at that point you're committed to using other globals like @EXPORT and/or @EXPORT_OK.

    The justification is that this is how it's done. You shouldn't need more justification than "because that's how it's done, and it generally works."

    Now if your question is asking about some other application of package globals, you'll need to be more specific. The symbol table is a powerful device, but not always the only (or even the right) tool for a given job. The barometer for justification in the more general case should be (1) Is it maintainable? (2) Does it work? (3) Is it the simplest approach?


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027889]
Front-paged by Corion
[Discipulus]: perlre and perlreref

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2018-03-20 08:05 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (248 votes). Check out past polls.