Do you know where your variables are? | |
PerlMonks |
Re: my $a and our $aby vinoth.ree (Monsignor) |
on Jan 06, 2016 at 08:00 UTC ( [id://1152055]=note: print w/replies, xml ) | Need Help?? |
my is a way to declare, none package variables, which are private,non-global variables separate from any package. So that the variable cannot be accessed in the form of $PackageName::variable our variables are, package variables, global variables and not private, they can be accessed outside the package with the qualified namespace, as $PackageName::variable Declaring a variable with our allows you to predeclare variables in order to use them under use strict without getting typo warnings or compile-time errors. Since Perl 5.6, it has replaced the obsolete use vars, which was only file-scoped, and not lexically scoped as is our. For example, the formal, qualified name for variable $x inside package main is $main::x. Declaring our $x allows you to use the bare $x variable without penalty (i.e., without a resulting error), in the scope of the declaration, when the script uses use strict or use strict "vars". The scope might be one, or two, or more packages, or one small block. Example:
All is well. I learn by answering your questions...
In Section
Seekers of Perl Wisdom
|
|