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

[perl #5087] used only once warning for lexicals?

From:
Michael G Schwern via RT
Date:
July 23, 2005 01:55
Subject:
[perl #5087] used only once warning for lexicals?
Message ID:
rt-3.0.11-5087-118192.17.0949371220378@perl.org
> [dha@panix.com - Fri Jan 05 01:38:47 2001]:
>
> Maybe there's a reason for it, but...
> 
> ~ 12:35:18$ perl -wce '$count = 1;'
> Name "main::count" used only once: possible typo at -e line 1.
> -e syntax OK
> 
> BUT...
> 
> ~ 12:35:52$ perl -wce 'my $count = 1;'
> -e syntax OK
> 
> Shouldn't that warning be raised, regardless of scope?

I agree.  In fact the argument for the warning is even stronger for a
lexical.  A global seen only once... well maybe some other package grabs
at it.  But a lexical declared but never used is useless.

About the only counter argument I can see is that issuing the warning
for lexicals will cause a lot of existing code to start yelping.  But
that's what warnings are for.  I for one would like to know about unused
lexicals.





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