Perl: the Markov chain saw | |
PerlMonks |
Re: Unclear about 'our'by LanX (Saint) |
on Dec 27, 2022 at 18:11 UTC ( [id://11149140]=note: print w/replies, xml ) | Need Help?? |
> Is this even what our is meant for? to expand on HaukeX's explanantion: our is meant (was introduced) to be analogue to my in declaring a "simple" var/symbol, but this time a package variable of the current package, not one private to the scope. Both are lexically scoped ° and with "simple" I mean not fully qualified, hence $name vs $Package::name strict -ness requires variables to be declared or fully qualified. before our was introduced, the only way to use a simple package var with strict was the vars pragma, which led to messy scopes.
one difference to my is that our vars are not destroyed at the end of scope, the alias is just released.
Cheers Rolf °) basically: available till the end of the surrounding block
UPDATEexpanded examples
Updatefor a better understanding: Perl4 didn't have strict or my resp. private variables. Every simple var automatically belonged to the current package and one often needed local for dynamic scoping at run time. our filled the conceptual hole to have compile-time checking for package vars in a more stringent way than use vars could provide.
In Section
Seekers of Perl Wisdom
|
|