perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan Gies <ryang...@livesite.net>
Subject Re: find all uninitialized variables?
Date Wed, 22 Feb 2006 23:47:45 GMT
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" <frank.maas@cheiron-it.nl>
> To: "'Harry Zhu'" <harry@greatlodge.com>; <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
> 
> 
> 
> 

Mime
View raw message