in reply to Catch references to undefined variables in other modules?

When I add use warnings; to your code like this:
#!/usr/bin/env perl use warnings; use strict; package a; our $x = 1; package main; print "a::x = ", $a::x, "\n"; # Fine print "a::z = ", $a::z, "\n"; # want to raise error here
I get the following warning messages:
Name "a::z" used only once: possible typo at ./647879.pl line 13. a::x = 1 Use of uninitialized value in print at ./647879.pl line 13. a::z =
Is this what you are looking for?

Replies are listed 'Best First'.
Re^2: Catch references to undefined variables in other modules?
by pc88mxer (Vicar) on Oct 29, 2007 at 17:22 UTC
    Not exactly, because the first warning won't show up if I happen to reference $a::z twice.

    The "use of uninitialized value" message is nice, but it's not telling me that $a::z was the cause of the problem.

    Basically I want to catch when the programmer mis-spelled a variable name, i.e. typed $a::z when they meant $a::x.

    The names in package a will be special in that they will only be defined within package a's lexical scope.