Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

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


    Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027889]
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (13)
As of 2014-09-18 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (121 votes), past polls