Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

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

Current Perl documentation can be found at perldoc.perl.org.

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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-19 04:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found