<?xml version="1.0" encoding="windows-1252"?>
<node id="701" title="How can I catch accesses to undefined variables/functions/methods?" created="1999-10-07 20:27:23" updated="2005-08-04 05:06:03">
<type id="834">
perlfaq nodetype</type>
<author id="519">
faq_monk</author>
<data>
<field name="doctext">


&lt;P&gt;
The 
&lt;FONT SIZE=-1&gt;AUTOLOAD&lt;/FONT&gt; method, discussed in [perlman:perlsub|Autoloading] and
[perlman:perltoot|AUTOLOAD: Proxy Methods], lets you capture calls to undefined functions and methods.

&lt;P&gt;
When it comes to undefined variables that would trigger a warning under &lt;CODE&gt;-w&lt;/CODE&gt;, you can use a handler to trap the pseudo-signal
&lt;CODE&gt;__WARN__&lt;/CODE&gt; like this:

&lt;P&gt;
&lt;PRE&gt;    $SIG{__WARN__} = sub {
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;        for ( $_&amp;#091;0&amp;#093; ) {         # voici un switch statement 
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;            /Use of uninitialized value/  &amp;amp;&amp;amp; do {
                # promote warning to a fatal
                die $_;
            };
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;            # other warning cases to catch could go here;
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;            warn $_;
        }
&lt;/PRE&gt;
&lt;P&gt;
&lt;PRE&gt;    };
&lt;/PRE&gt;
&lt;P&gt;
</field>
</data>
</node>
