in reply to Re^3: Best practices - if any? (our)
in thread Best practices - if any?
Variables declared with our create a package variable and a lexically scoped variableThat suggests any use of our creates two variables. It doesn't. It creates an alias (another name) for the variable - the alias is lexically scoped. And no matter how many times you use our, it doesn't create new variables over and over again - unlike my.
It does warn. But even if you put all the lines in different scopes (no warnings then), it's still the same variable when using our:my $foo++; say $foo; my $foo++; say $foo; our $bar++; say $bar; our $bar++; say $bar; __END__ 1 1 1 2
{my $foo++; say $foo;} {my $foo++; say $foo;} {our $bar++; say $bar;} {our $bar++; say $bar;} __END__ 1 1 1 2
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Best practices - if any? (our)
by shmem (Chancellor) on Feb 22, 2010 at 12:49 UTC |