I've been frustrated with the "Use of uninitialized value" warning myself, and was hoping someone could shed some light on it as well. Point being, this will issue the warning:

    #!/usr/bin/perl -Tw
    sub max { return $_[0] > $_[1] ? $_[0] : $_[1]; }
    max();

In what seems like logic, the undef value should behave like zero or empty string when using operators like: '.' ',' 'eq' 'lt' '>' etc...

--- Yes, this should taken to beginners@perl.org ---

I believe the crux of Harry's problem is that warnings are only issued as the code is executed, and we want to find unintialized variables without having to make an uber test-case which calls every subroutine.

Anyway, here's a (I presume very frowned-upon) way to get around the annoying warning messages, or maybe you can use it to silently capture the warnings as your application runs over time:

    $SIG{__WARN__} = \&_sigwarn; # notice not declared local!

    sub _sigwarn {
        my $msg = shift || return;
        return if $msg =~ "^Use of uninitialized value in";
        print STDERR $msg;
    }

Harry Zhu wrote:
"use strict" will find the undeclared/undefined variables.

something  like
my $var;

and later on used in the program will not be find by the "use strict", but will cause "use uninitialized variables" warnings if -w switch is on.

Harry




----- Original Message ----- From: "Frank Maas" <[EMAIL PROTECTED]>
To: "'Harry Zhu'" <[EMAIL PROTECTED]>; <modperl@perl.apache.org>
Sent: Wednesday, February 22, 2006 5:17 PM
Subject: RE: find all uninitialized variables?



Is there an easy way (a tool) to locate all uninitialized variables for modperl modules in a dirctory so I can initilized them and get rid of the annoying warnings? Googlling on the internet seems no useful results. Some one shield
me a light?


Does not seem to be a specifiec mod_perl thing, but hey. Have you tried "use strict"? If that does not do your trick, then elaborate on what you mean by 'uninitialized'?

Gr/F




Reply via email to