Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: does perl have a concept of "int main()"? (variable scoping question)

by shmem (Chancellor)
on Dec 05, 2013 at 20:34 UTC ( #1065837=note: print w/replies, xml ) Need Help??

in reply to does perl have a concept of "int main()"? (variable scoping question)

Ah, perl variables. See perldata for starters.

Perl has global variables (and special global variables, see perlvar) which live in the symbol table of a package (or the "anypackage", i.e. they are available everywhere); then aliased specials, localized globals, lexically scoped, masked and state variables. Am I missing some?

The perl documentation provides a wealth of information about each variable kind. Start with perldata, look up my, our, local. The monastery has good writeups about various issues regarding each variable kind, i.e. my/local, space/time (was: Re: The difference between my and local).

By default, without useing strict, each variable is autovivified upon first use and its identifier stored in the symbol table of the current package, which defaults to main. The symbol table itself is a hash (default %main:: - note the two colons which are package identifiers/delimiters). The variables in each package are not globals - not even the variables in package main:

perl -le '$foo ="bar"; package Bar; print ">$foo<";package main; print + ">$foo<"' >< >bar<

Well... that's for starters. I wish you a good time grinding manual pages and exploring the depths of this Monastery.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1065837]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2017-05-27 02:27 GMT
Find Nodes?
    Voting Booth?