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

Re: [perl #23630] problem with "used only once" warning

From:
Fergal Daly
Date:
August 29, 2003 02:38
Subject:
Re: [perl #23630] problem with "used only once" warning
Message ID:
200308291038.17507.fergal@esatclear.ie
On Friday 29 August 2003 01:35, John Peacock wrote:
> +            NOTE: $c and @c are the same variable name for this purpose;
> if +            two or more variables with the same name and different
> prefixes +            are used only once, it will not trigger this warning.
>
> > speaks about variable names rather than variables but I wonder how many
> > people get that the subtle distinction without finding out the hard way,
>
> How about something like that?  I suppose we could also suggest taking a
> look at an entry describing globs (but that seems like too detailed for a
> warning).

perl -we 'sub c{print $c}

So we need to mention subs, filehandles and globs. How about being more 
explicit

+            NOTE: This warning detects symbols that have been used only
+            once so c, c, c, sub c, c(), &c, *c and c (the filehandle) are
+            considered the same; if a program uses $c only once but also
+            uses sub c, it will not trigger this warning.

One way to fix it is to expand xpvgv's xgv_flags member to have a MULTI flag 
for each type of variable, so instead of just flagging that the NAME has been 
used it would flag that $NAME or %NAME has been used as. I can't see that 
being a popular option.

> Personally, I don't think the likelyhood of someone getting bit by this
> particular "thinko" warrants confusing the docs.

The docs will only be confusing because the feature is confusing and that's 
without even mentioning the fact that using a symbol only once is ok when 
it's used as a sub.

Currently I think everybody (everybody in my office anyway) is sure about what 
this warning does and everbody is wrong. Changing the docs will make less 
people sure but more people right. Changing the feature would be even better 
if there was a nice way to do it,

F




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