Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: About packages and scopes

by staeryatz (Monk)
on Nov 19, 2001 at 22:25 UTC ( [id://126325]=note: print w/replies, xml ) Need Help??


in reply to About packages and scopes

You asked if all package variables are global. According to my Perl 5 book, that statement is false.

From what I've read about Perl packages (I'm still also learning it, myself), is that "global" package variables are global to the package, and not neccessarily global to the program.

$PackageName::variablename would be the syntax to access these "global" variables.

Replies are listed 'Best First'.
Re: Re: About packages and scopes
by nlafferty (Scribe) on Nov 19, 2001 at 22:32 UTC
    It is possible that i assumed it meant the program when it was the package. But wouldn't that make it lexical? I need a beginners guide to perl packages. This was from the O'reilly Programming Perl. Upon futher inspection, there are no global variables in perl, just package variables.
      There are a handful of global variables -- punctuation ones, mostly.

      _____________________________________________________
      Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
      s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Wouldn't that make it lexical? Good question.

      The answer is no, because lexical variables expire once they are outside a certain scope, and cannot be referenced outside of that scope.

      Global package variables on the other hand, can be accessed at any time, as long as you use the package names and colons preceeding the variable name.

      Hope that clears up a few things...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://126325]
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-24 04:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found