ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> perl5-porters
perl5-porters
Re: [perl #56530] [RESOLVED] used only once: possible typo
by Bram other posts by this author
Jul 5 2008 11:57AM messages near this date
Re: [perl #56530] [RESOLVED] used only once: possible typo | Re: [perl #18049] [RESOLVED] Storable seg faults under perl 5.8.0 solaris, maximal 64bit
Citeren Toralf Förster <toralf.foerster@[...].de> :

>  At Friday 04 July 2008 23:11:53 Bram via RT wrote :
> > According to our records, your request regarding
> >   "<variable> used only once: possible typo"
> > has been resolved.
> >
> > If you have any further questions or concerns, please respond to   
> > this message.
> >
> > For other topics, please create a new ticket.
> >
> > Please don't feel obligated to say "Thanks" or "Kudos" or "I owe   
> > you a beer" -- if you respond to this message it will reopen the   
> > ticket. If you must, please send email directly to the person who   
> > handled your ticket, and not to the tracking system.
> >
> > <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=56530 >
> >
> 
>  Yes, "perl works as designed" might be an answer.
>  OTOH I'm wondering whether perl could be improved to not give a   
>  warning in such a case.
>  The term "used only once" is true for a line like "$foo = 1; " if   
>  ther's no further access to
>  the variable foo, but the given example shows that the variable is   
>  used after it is incremented...
> 

What really counts is how many times the variable is written, which is  
indeed not always the same as used.

In the case of your example: $counter is written only once in the  
script. The value is accessed and then incremented in a single  
operation.
This might be an error, this might not be an error.

What if your example was for example:

seq 1 7 | perl -we '$counter = 1; while (<STDIN> ) { print "line  
break\n" if ($couter++ % 3 == 0); print "line $counter = $_" }'


Personally, I don't really see a value (or a way) in imporoving it...


You don't want to see the warning?
Use a lexical variable.

You don't want to bother use a lexical variable?
Then disable warnings.


Warnings are about things that could be wrong.
If you write the name of a global variable only once in your script  
then that certainly could be wrong.


Kind regards,

Bram
Thread:
Toralf Foerster
Bram

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved