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

[perl #2915] my $x; our $x; does not give "masked" warning

Thread Next
From:
Michael G Schwern via RT
Date:
July 12, 2005 20:30
Subject:
[perl #2915] my $x; our $x; does not give "masked" warning
Message ID:
rt-3.0.11-2915-117143.13.4399303496161@perl.org
> [mjtg@cus.cam.ac.uk - Thu Mar 30 21:52:59 2000]:
> 
> Shouldn't
> 
>     perl5.6.0 -we 'my $x; our $x; $x=0'
> 
> generate some sort of "redeclared" warning?    The other cases
> (two "my"s or two "our"s or "our" before "my") all do.

This is still an issue in 5.9.x.  I'd agree, there should be a warning
particularly because all other combinations issue a warning:

$ bleadperl -lwe 'my $x = 42; our $x = 23; print $x'
23
$ bleadperl -lwe 'my $x = 42; my $x = 23; print $x'
"my" variable $x masks earlier declaration in same scope at -e line 1.
23
$ bleadperl -lwe 'our $x = 42; my $x = 23; print $x'
"my" variable $x masks earlier declaration in same scope at -e line 1.
23
$ bleadperl -lwe 'our $x = 42; our $x = 23; print $x'
"our" variable $x masks earlier declaration in same scope at -e line 1.
23


> And is it appropriate that
> 
>         perl5.6.0 -we 'our $x'
> 
> generates a "used only once", but the corresponding "my" does not?

This appears to have been resolved.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About