Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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'


Comment on Re: does perl have a concept of "int main()"? (variable scoping question)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1065837]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-11-25 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls