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

This newbie has a package that defines a fair number of (constant) messages using:
package foo; ... our $enqmsg = pack ("C*", 0x01, 0x55, 0x22 ...);
The "main" program then uses those messages in subroutine calls such as
printmsg ($foo::enqmsg, ...);
Since many of these messages are used only once, I receive a great number of warnings about them only being used once. Is there something "suboptimal" about the way that I have structured this ? Or should I simply define an "extraneous"
@msglist=($foo::enqmsg,...);
at the top of the program to force a second reference ? Is there anything that can be done in the defining package so as not to burden "users" of the package ? Thanks, Scott.

Replies are listed 'Best First'.
Re: Avoiding "only one reference" warnings
by BrowserUk (Patriarch) on Oct 15, 2003 at 01:14 UTC

    If these package variables don't change, you can avoid the need for disabling the warning by useing constant;


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

Re: Avoiding "only one reference" warnings
by pzbagel (Chaplain) on Oct 15, 2003 at 00:28 UTC

    What you want is to disable the offending warning message. This can be accomplished like so:

    #!/usr/bin/perl + use warnings; no warnings qw /once/; use strict;

    Notice that you can't use -w because it is all or nothing, you must use the "use warnings" syntax if you want to be able to disable individual warning messages.

    Check out perllexwarn.

    HTH