SPUG: Annoying "name only used once" msg from -w

Doug Beaver dougb at scalar.org
Thu Apr 27 11:53:45 CDT 2000

On Thu, Apr 27, 2000 at 09:17:51AM -0700, Richard Anderson wrote:

> I often set a variable in the main program that is only referenced in
> a subroutine that is in another file.  I don't want to explicitly pass
> it to the subroutine because I am dealing with large numbers of
> parameters, so I refer to it in the subroutine as $main::foo.
> When I use the perl -w command line option, I get annoying messages
> like Name "main::date" used only once: possible typo ...
> Is there any other way to shut this message off other than:
> (1) Adding a gratuitous reference to the variable
> (2) Explicitly passing the variable to the subroutine
> (3) Turning off the -w option
> (4) Copying the subroutine code into the file containing the main
> program

If you're using that many variables inside of the subroutine, you might
want to explore populating an anonymous hash and passing that from
function to function much like the way people pass structs around in C

my %args = (
    d => 1,
    e => 2,
    f => 3,


sub func {
  my ($hash) = @_;
  my $d = $hash->{d};
  my $e = $hash->{e};
  my $f = $hash->{f};

  # blah blah blah

Otherwise, if you're using perl 5.6, you can disable the 'used only
once' messages by putting:

no warnings 'once';

in your script.  If you have perl 5.6, you might want to investigate the
perllexwarn and warnings perldocs, there's a lot of cool stuff in there
that you can do to manipulate warnings and turn off bothersome warnings.
I use it to turn off those 'Use of uninitialized value' warnings because
they bug me.  ;-)


Smithers: I'm afraid we have a bad image, Sir.  Market research shows
          people see you as somewhat of an ogre.
   Burns: I ought to club them and eat their bones!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace "action" below by subscribe or unsubscribe
           Email to majordomo at pm.org: "action" spug-list your_address

More information about the spug-list mailing list