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

[perl #2915] Inconsistent warnings with "our"

Thread Next
Michael G Schwern via RT
July 14, 2005 16:17
[perl #2915] Inconsistent warnings with "our"
Message ID:
So, to sum up... I think we all agree these should all warn.

    my $x;  our $x;  # this currently does not
    our $x; my $x;
    my $x;  my $x;
    our $x; our $x;

and that this should not

    package Foo;
    our $x;

    package Bar;
    our $x;

but this appears to be up in the air:

    package Foo;
    my $x;

    package Bar;
    our $x;

Currently this warns.  Rick's patch to fix "my $x; our $x;" changes this
so that it does not warn on the grounds that the "package Foo; our $x;
package Bar; our $x" case doens't warn either.  But I say that's a
special case to do with the fact that our's mix of two scoping
mechanisms, lexical and package, runs afoul of multi-package-in-one-file
programming idioms.

    package Foo;
    our @ISA = qw(...);  # or $VERSION or @EXPORT or ...

    package Bar;
    our @ISA = qw(...);

There's no corresponding idiom for "package Foo; my $x; package Bar; our
$x" or vice-versa.  Therefore, it should warn about the mask.

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