Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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 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
Chatterbox?
[Eily]: the pun doesn't work so well with "he lost a diacritic" though :P
[LanX]: Obelix might offer to find it again ...
[LanX]: not much to translate anyway since Goscinny died
[Eily]: https://en. wikipedia.org/ wiki/List_of_Aster ix_characters some of the names were changed to include a new pun
[LanX]: sure some are even funnier now
[LanX]: some lost because they were not translated like Epidemais
[LanX]: some of the english names are funny too

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (14)
As of 2017-05-24 15:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?