Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

How can I catch accesses to undefined variables/functions/methods?

by faq_monk (Initiate)
on Oct 08, 1999 at 00:27 UTC ( #701=perlfaq nodetype: print w/ replies, xml ) Need Help??

Current Perl documentation can be found at

Here is our local, out-dated (pre-5.6) version:

The AUTOLOAD method, discussed in Autoloading and AUTOLOAD: Proxy Methods, lets you capture calls to undefined functions and methods.

When it comes to undefined variables that would trigger a warning under -w, you can use a handler to trap the pseudo-signal __WARN__ like this:

    $SIG{__WARN__} = sub {

        for ( $_[0] ) {         # voici un switch statement 

            /Use of uninitialized value/  && do {
                # promote warning to a fatal
                die $_;

            # other warning cases to catch could go here;

            warn $_;


Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-11-25 07:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (672 votes), past polls