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

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

Michael G Schwern via RT
July 23, 2005 01:55
[perl #5087] used only once warning for lexicals?
Message ID:
> [ - 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. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About