note
BioLion
<p>Using [cpan://diagnostics] for more verbose warnings should make things more clear:</p>
<readmore>
<code>
#! usr/bin/perl
use strict;
use warnings;
use diagnostics;
my $scalar_ref=*foo{SCALAR};
print "scalar ref defined\n" if defined $scalar_ref;
#------------------------#
my %hash=();
my $hash_ref=*hash{HASH};
print "hash ref defined\n" if defined $hash_ref;
__END__
Output:
Name "main::hash" used only once: possible typo at test.pl line 11 (#1)
(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
provided for this purpose.
NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.
Name "main::foo" used only once: possible typo at test.pl line 7 (#1)
scalar ref defined
</code>
</readmore>
<p>The key part explaing the difference in ouput for your two scripts is :
<blockquote>NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.</blockquote>
</p>
<p>There is also a good discussion of a similar problem in [id://760610]. HTH.</p>
<div class="pmsig"><div class="pmsig-656648">
<i>Just a something something...</i>
</div></div>
790258
790258