develooper Front page | perl.perl5.porters | Postings from August 2001

RE: [ID 20010820.007] variables being hidden

August 21, 2001 07:21
RE: [ID 20010820.007] variables being hidden
Message ID:
Hugo van der Sanden wrote:
> "Giroux, Mike (Exchange)" <> wrote:
> :It's also, quite often, intended behaviour.
> I think it is only rarely intended behaviour to declare a lexical
> variable that you assign to but never use. It would not be
> unreasonable to have an optional warning for such things, though
> it might be a bit tricky to detect.

Interesting...  It could be tricky to tell the difference between

:> my $var1=0;
:> foreach my $var2 (@allVars) {
:>   if ($var2 eq $someValue) {
:>      my $var1=1;
:>   }
:> }
:> print $var1;

and some construct like

my ($true, $false) = (1,0);

in code where $false is never used, let's say.  It's a bogus example,
don't shoot me :)

Is there any way we could detect that a lexical 
	1) hides another lexical
AND   2) is assigned to but never used?

That would cover John's problem nicely, and probably wouldn't generate
too many spurious warnings.

However, my knowledge of the internals isn't anywhere near where it
would have to be for me to offer a patch, sorry. :(
Mike Giroux
via, but not for, Bear-Stearns

Bear Stearns is not responsible for any recommendation, solicitation, 
offer or agreement or any information about any transaction, customer 
account or account activity contained in this communication.
*********************************************************************** Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About