[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
Re: [PATCH lib/lib.pm 5.005_63] Removing use of vars.pm
On Sat, Jan 22, 2000 at 05:17:13AM -0700, Tom Christiansen wrote:
> >Also, our() might not be the right thing. Sometimes, use vars is the right
> >thing, if you have multiple packages in a file and don't want to share.
>
> use vars and our() both allow you to refer to a package variable
> without its package component. But how is it that use vars somehow
> helps you in multiple packages? That sounds like importing.
I believe he's refering to this possiblity:
package Foo;
use vars qw($this);
$this = "Foo";
package Bar;
use vars qw($this);
$this = "Bar";
package main;
print $Foo::this;
That's fine. But if you robotically replace "use vars" with "our":
package Foo;
our $this = "Foo";
package Bar;
our $this = "Bar";
package main;
print $Foo::this;
You wind up with a lexical scoping problem:
"our" variable $this masks earlier declaration in same scope at -e line 1.
Name "Bar::this" used only once: possible typo at -e line 1.
Foo
I'll watch for this possibility and leave files with multiple package
definitions alone.
--
Michael G Schwern schwern@pobox.com
http://www.pobox.com/~schwern
/(?:(?:(1)[.-]?)?\(?(\d{3})\)?[.-]?)?(\d{3})[.-]?(\d{4})(x\d+)?/i
- Follow-Ups from:
-
Gurusamy Sarathy <gsar@ActiveState.com>
- References to:
-
Tom Christiansen <tchrist@chthon.perl.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]