in reply to Re: Unusual variable declaration
in thread Unusual variable declaration
I would not call that "declaring a variable". my $var declares a variable.
our $var; merely instructs perl to allow you to access the global variable $<current_package>::var using the short name. No new variable gets created.
package Foo; $Foo::var = 1; print "package var is $Foo::var\n"; { our $var; print "same variable using short name is $var\n"; $var = 2; print "using short name changed to $var\n"; print "package var is now $Foo::var\n"; } print "I said package var is now $Foo::var\n"; $Foo::var = 3; print "And now it's $Foo::var\n"; { our $var; print "still the same variable using short name is $var\n"; }
If it were my instead of <our> not only you would not access the package variable $Foo:var, but you'd also declare two separate variables in those two blocks!
Jenda
1984 was supposed to be a warning,
not a manual!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Unusual variable declaration
by LanX (Saint) on Nov 04, 2019 at 14:44 UTC | |
|
Re^3: Unusual variable declaration
by davido (Cardinal) on Nov 04, 2019 at 19:28 UTC | |
by LanX (Saint) on Nov 04, 2019 at 22:25 UTC | |
by Jenda (Abbot) on Nov 05, 2019 at 11:19 UTC | |
by LanX (Saint) on Nov 05, 2019 at 12:27 UTC | |
by Jenda (Abbot) on Nov 05, 2019 at 16:33 UTC | |
|