develooper Front page | perl.perl5.porters | Postings from July 2012

Re: [perl #113974] package NAMESPACE manpage comments

Thread Previous | Thread Next
Ricardo Signes
July 5, 2012 19:42
Re: [perl #113974] package NAMESPACE manpage comments
Message ID:
>    Actually, as near as I can tell, they are at the Perl-global level --
> and exist outside of packages -- and outside of files.
> They are accessible to any package that "uses them", but don't
> belong to any package.
> They are the true GLOBAL variables, but only accessible in those packages
> that "use vars" them.
> At least that's how I understand it from my testing...if that's not
> what other people think, I'd like to know why given the posted test
> progs...

I wrote a blog post about what use vars vars are, some time ago.  Here:

It's not very complicated.  It works like this:

When you create an alias in your package to a variable in another package, it's
marked "imported" so that you can refer to it easily.  This is great when you
want to get constant $OK from HTTP::Whatever and just say $OK.  The Exporter
does *YourPkg::OK = \$HTTP::Whatever::OK and the little "I was imported!" flag
is set on $YourPkg::OK so that when you say "$OK" in YourPkg, it's permitted
because you specifically asked for that variable from elsewhere.

"use vars" means "mark these variables as imported, even though they are not."

If you "use vars '$x'" in package Foo, then anywhere that you switch into
package Foo, $x will mean $Foo::x (unless it has been shadowed by a lexial

In no case does this $x become a superglobal, available without qualification
everywhere.  It's always accessible as $Foo::x, sometimes as $x, and that's

"our" variables are available by short name in the enclosing lexical scope.

"use vars" variables are available by short name whenever in the importing


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About