Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: my $a and our $a

by Marshall (Canon)
on Jan 06, 2016 at 07:15 UTC ( [id://1152048]=note: print w/replies, xml ) Need Help??


in reply to my $a and our $a

First NEVER use $a or $b as a program variable as these have special meaning to Perl in terms of sorting.

Almost all of your variables should be "my whatever"...that means 99.9%. These are lexically scoped variables within a single compilation unit. The addresses of these variables are not fixed, they are allocated on the stack. The same name can be reused again and again within different loops. "my $name" in one loop is not the same as "my $name" in another loop.

An "our" variable is different. This is like a C static. This variable is global and goes into a special symbol table. These variables can be accessed by other modules (there is no way to do that with a "my" variable).

"our" variables should be used very sparingly and for good reasons.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-19 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found