perl -ws and "used only once" warnings

D

Dan Jacobson

Perhaps if one of you know the exact bug, you could file a report for
me.

$ cat /tmp/v
#!/usr/bin/perl -ws
if ($xyz) { print "$xyz\n" }
if ($g) {print 66} else {print 55}
$ /tmp/v
Name "main::g" used only once: possible typo at /tmp/v line 3.
55

because $xyz is used twice, the perlrun page authors wouldn't have
triggered the bug when adding -w to their example.

The bug is: g shouldn't be warned about.
Quick hack:
if ($g) {print 65+$g} else {print 55}
 
A

Anno Siegel

Dan Jacobson said:
Perhaps if one of you know the exact bug, you could file a report for
me.

$ cat /tmp/v
#!/usr/bin/perl -ws
if ($xyz) { print "$xyz\n" }
if ($g) {print 66} else {print 55}
$ /tmp/v
Name "main::g" used only once: possible typo at /tmp/v line 3.
55

because $xyz is used twice, the perlrun page authors wouldn't have
triggered the bug when adding -w to their example.

Of course not.
The bug is: g shouldn't be warned about.

Why do you think it shouldn't?

Anno
 
B

Brian McCauley

Dan Jacobson said:
Perhaps if one of you know the exact bug, you could file a report for
me.

No, you can file it yourself.
#!/usr/bin/perl -ws
if ($xyz) { print "$xyz\n" }
if ($g) {print 66} else {print 55}
$ /tmp/v
Name "main::g" used only once: possible typo at /tmp/v line 3.
55

because $xyz is used twice, the perlrun page authors wouldn't have
triggered the bug when adding -w to their example.

The bug is: g shouldn't be warned about.

No it isn't.

If there is a bug it's a documentation bug in perlrun, which should
perhaps say in the description of -s:

When using this option on a script with warnings enabled you
may get a lot of spurious "used only once" warnings so you may
want to switch those off.

On the other hand, once you've had the warning this should be
self-evident so perhaps its not worth bloating perlrun.pod.

Incidently the perldiag entry for this warning says:

(W once) Typographical errors often show up as unique
variable names. If you had a good reason for having a
unique name, then just mention it again somehow to
suppress the message. The "our" declaration is pro-
vided for this purpose.

The bit about mentioning the variable is correct.

The bit about our() being provided for this purpose is wrong. The
word "provided" should be something like "useful".

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top