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

[email protected] (_brian_d_foy)
Newsgroups perl.perlfaq.workers,perl.documentation
Message-ID <041120022020160448%[email protected]>
* Brian McCauley suggested that this answer use warnings instead of black magic


Index: perlfaq7.pod
===================================================================
RCS file: /cvs/public/perlfaq/perlfaq7.pod,v
retrieving revision 1.10
diff -u -d -r1.10 perlfaq7.pod
--- perlfaq7.pod        4 Sep 2002 22:33:45 -0000       1.10
+++ perlfaq7.pod        5 Nov 2002 02:16:45 -0000
@@ -675,31 +675,16 @@
         print "No such command: $string\n";
     } 
 
-=head2 How can I catch accesses to undefined variables/functions/methods?
+=head2 How can I catch accesses to undefined variables, functions, or methods?
 
 The AUTOLOAD method, discussed in L<perlsub/"Autoloading"> and
 L<perltoot/"AUTOLOAD: Proxy Methods">, lets you capture calls to
 undefined functions and methods.
 
 When it comes to undefined variables that would trigger a warning
-under C<-w>, you can use a handler to trap the pseudo-signal
-C<__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 $_;
-       }
+under C<use warnings>, you can promote the warning to an error.
 
-    };
+       use warnings FATAL => qw(uninitialized);
 
 =head2 Why can't a method included in this same file be found?
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.