saintex has asked for the wisdom of the Perl Monks concerning the following question:

hello Monks,
I have a strange warning,
when I try:
my %q= %SQL_Wrapper::q;
I have:
Name "SQL_Wrapper::q" used only once: possible typo at ...
But I don't know how avoid this warning.
I know I used %SQL_Wrapper::q and I will never use it again, because It is an assignment by value.

From know I will use %q (not %SQL_Wrapper::q).
How can I avoid that warning message?
Thank you!

Replies are listed 'Best First'.
Re: my hash used only once: possible typo
by ikegami (Patriarch) on Aug 23, 2010 at 16:40 UTC
    I presume you are using
    our %q;
    in SQL_Wrapper? Change it to
    use vars qw( %q );

    Of course, you could provide a reasonable interface instead

    my %q = SQL_Wrapper->q;
      what is the difference beetween "our" and "use vars"?
      Thank you for your answer
Re: my hash used only once: possible typo
by kennethk (Abbot) on Aug 23, 2010 at 16:18 UTC
    If you are certain that a warning is spurious, you can disable it locally using no warnings;. It is generally considered good form to disable warnings in as small a scope as possible and to only disable the known spurious warning. In this case, the warning is once (see Category Hierarchy in perllexwarn), so you could use the code:

    no warnings "once"; my %q= %SQL_Wrapper::q; use warnings;

    or you could use a do, which is what I usually use in this sort of scenario

    my %q= do{ no warnings "once"; %SQL_Wrapper::q; };
Re: my hash used only once: possible typo
by james2vegas (Chaplain) on Aug 23, 2010 at 16:50 UTC
    Are you sure this warning is spurious? Basically it means that %SQL::Wrapper::q is not used anywhere else, at all, for example this code doesn't produce the warning:
    { package SQL_Wrapper; use strict; use warnings; our %q; } package main; use strict; use warnings; my %q = %SQL_Wrapper::q; $q{f} = 42;
    but this code does:
    { package SQL_Wrapper; use strict; use warnings; # our %q; } package main; use strict; use warnings; my %q = %SQL_Wrapper::q; $q{f} = 42;
    What is setting/changing %SQL_Wrapper::q in your program or modules that your program is using?