Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by shmem (Canon)
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1065837]
help
Chatterbox?
Discipulus is Corion reading 'Gory details of parsing quoted constructs'?..
[perldigious]: That's awesome erix. One of my work friends, who coincidentally convinced me to learn Perl originally, has a Finnish pen-pal. I showed him this and he immediately wanted to send it along to her.

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2016-12-06 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (112 votes). Check out past polls.