find all uninitialized variables?

find all uninitialized variables?

am 23.02.2006 00:12:14 von Harry Zhu

This is a multi-part message in MIME format.

------=_NextPart_000_07C6_01C637D3.2026AAF0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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?

Harry Zhu
------=_NextPart_000_07C6_01C637D3.2026AAF0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable



charset=3Diso-8859-1">




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

 

Harry Zhu


------=_NextPart_000_07C6_01C637D3.2026AAF0--

RE: find all uninitialized variables?

am 23.02.2006 00:17:21 von Frank Maas

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

Re: find all uninitialized variables?

am 23.02.2006 00:24:51 von Harry Zhu

"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"
To: "'Harry Zhu'" ;
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




--
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.375 / Virus Database: 268.0.0/266 - Release Date: 2/21/2006

Re: find all uninitialized variables?

am 23.02.2006 00:27:22 von Tyler MacDonald

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.

If you really want to cause your scripts to crash on every
uninitialized variable so you have to go in and fix it, you can do this:

use warnings FATAL => 'uninitialized';

Cheers,
Tyler

Re: find all uninitialized variables?

am 23.02.2006 00:37:05 von Harry Zhu

Say I have a file directory with hundreds of modules, I want to know if
there is a tool I can scan and identify the uninitalized variables in all
the files once (or through a loop) without actually running through all the
pages.

Harry


----- Original Message -----
From: "Tyler MacDonald"
To: "Harry Zhu"
Cc: "Frank Maas" ;
Sent: Wednesday, February 22, 2006 5:27 PM
Subject: Re: find all uninitialized variables?


> 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.
>
> If you really want to cause your scripts to crash on every
> uninitialized variable so you have to go in and fix it, you can do this:
>
> use warnings FATAL => 'uninitialized';
>
> Cheers,
> Tyler
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.375 / Virus Database: 268.0.0/266 - Release Date: 2/21/2006
>
>

Re: find all uninitialized variables?

am 23.02.2006 00:47:45 von Ryan Gies

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"
> To: "'Harry Zhu'" ;
> 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
>
>
>
>

Re: find all uninitialized variables?

am 23.02.2006 00:50:50 von Tyler MacDonald

Harry Zhu wrote:
> Say I have a file directory with hundreds of modules, I want to know if
> there is a tool I can scan and identify the uninitalized variables in all
> the files once (or through a loop) without actually running through all the
> pages.

If you don't want to run through all the pages and possibilites
yourself, I reccommend selenium:

http://www.openqa.org/selenium/

That will allow you to create test suites that run in your browser
that go through every page and try to do things on it. Then you can check
your error logs and, if your test does everything a regular user possibly
could, you'll have a list of all your uninitialized variables, as well as
possibly turning up some bugs you hadn't tested for before.

There's no easy way to do tell whether or not a variable is going to
be used throughout the course of a webpage, except watching the warnings and
running every single code path that web page has (logged in, not logged in,
filled out this form element before hitting "submit", didn't, etc.)

You might be able to do detect global variables that aren't used by
a package, but nowadays over 90% of variables are local (my) variables, and
still... What if the variable isn't initialized in one module, because
another module initializes it?

Devel::Cover can help to see if you're running every single code
path possible in the code you care about; Devel::Trace and Devel::Profile
can help to see exactly what code you're actually running and when.

If you just want to get rid of the warnings and don't care whether
or not the module is using it's variables cleanly, you can add the line

no warnings 'uninitalized';

to each module that you're being annoyed by.

- Tyler

Re: find all uninitialized variables?

am 23.02.2006 00:51:50 von Frank Wiles

On Wed, 22 Feb 2006 17:37:05 -0600
"Harry Zhu" wrote:

> Say I have a file directory with hundreds of modules, I want to know
> if there is a tool I can scan and identify the uninitalized variables
> in all the files once (or through a loop) without actually running
> through all the pages.

Not really. In simple situations, you could regex and find some of
them. But you won't find them all. Take for example:

my $var = $self->get_var;

Is $var initialized? Dunno, depends on what the get_var method
does and returns, which depends on whatever it calls, etc. You can't
really tell except at runtime.

But, you can just turn off this particular warning in your code by
doing this:

use warnings;
no warnings qw( uninitialized );

---------------------------------
Frank Wiles
http://www.wiles.org
---------------------------------

Re: find all uninitialized variables?

am 23.02.2006 00:53:19 von jonathan vanasco

if you
use strict ;
use warnings;

any module that you load w/an uninitialized variable will print an error

what i do is as follows:

use warnings & strict in $APP_DIR/etc/startup.pl
include all my modules in $APP_DIR/etc/startup.pl

tail -f $APP_DIR/logs/error.log

sudo /usr/local/apache2/bin/apachectl restart

that will try and include all the modules i listed in startup.pl

if there's an uninitialized value, apache won't start up, and it will
tell me the line.
i fix that, and try to start apache again

if you preload, you don't have to run through the pages - but it
will crash on the first variable


On Feb 22, 2006, at 6:37 PM, Harry Zhu wrote:

> Say I have a file directory with hundreds of modules, I want to
> know if there is a tool I can scan and identify the uninitalized
> variables in all the files once (or through a loop) without
> actually running through all the pages.
>
> Harry

Re: find all uninitialized variables?

am 23.02.2006 01:16:04 von jonathan vanasco

a_ you should preload modules into mod_perl already to take advantage
of shared memory

b_ you can automate listing the files using File::Find and some
sprintf magic

====
my @perl_files ;
use File::Find;
find(\&wanted, ( /paths/to/modules ) );
sub wanted
{
my %pathname = map { $_ , 1 } split '/' , $File::Find::name;

# kill the subversion files
return if ( $pathname{'.svn'} );

# only pm
return unless ( substr( $_ , -5 ) eq '.pm' );

push @ perl_files , $File::Find::name;
}
===




On Feb 22, 2006, at 9:10 PM, wrote:

> Looks like what I needed (if works) but with a lot of editting: use
> Module1,
> use Module2, ..., use ModuleN.
>
>
> Thanks.
>
> Harry
>
>
>
>
> ----- Original Message -----
> From: "Jonathan Vanasco"
> To: "Harry Zhu"
> Cc: "mod_perl List"
> Sent: Wednesday, February 22, 2006 3:53 PM
> Subject: Re: find all uninitialized variables?
>
>
>> if you
>> use strict ;
>> use warnings;
>>
>> any module that you load w/an uninitialized variable will print an
>> error
>>
>> what i do is as follows:
>>
>> use warnings & strict in $APP_DIR/etc/startup.pl
>> include all my modules in $APP_DIR/etc/startup.pl
>>
>> tail -f $APP_DIR/logs/error.log
>>
>> sudo /usr/local/apache2/bin/apachectl restart
>>
>> that will try and include all the modules i listed in startup.pl
>>
>> if there's an uninitialized value, apache won't start up, and it will
>> tell me the line.
>> i fix that, and try to start apache again
>>
>> if you preload, you don't have to run through the pages - but it
>> will crash on the first variable
>>
>>
>> On Feb 22, 2006, at 6:37 PM, Harry Zhu wrote:
>>
>>> Say I have a file directory with hundreds of modules, I want to
>>> know if there is a tool I can scan and identify the uninitalized
>>> variables in all the files once (or through a loop) without
>>> actually running through all the pages.
>>>
>>> Harry
>>
>>
>
>

Re: find all uninitialized variables?

am 23.02.2006 01:47:13 von Harry Zhu

Thanks. But I did a simple "svn list -R" and get what I want into a file and
some quick substitution editting. Now I have a test.pl file to load it in
Apach conf.

Harry

----- Original Message -----
From: "Jonathan Vanasco"
To: "Harry Zhu"
Cc: "mod_perl List"
Sent: Wednesday, February 22, 2006 6:16 PM
Subject: Re: find all uninitialized variables?


>
> a_ you should preload modules into mod_perl already to take advantage of
> shared memory
>
> b_ you can automate listing the files using File::Find and some sprintf
> magic
>
> ====
> my @perl_files ;
> use File::Find;
> find(\&wanted, ( /paths/to/modules ) );
> sub wanted
> {
> my %pathname = map { $_ , 1 } split '/' , $File::Find::name;
>
> # kill the subversion files
> return if ( $pathname{'.svn'} );
>
> # only pm
> return unless ( substr( $_ , -5 ) eq '.pm' );
>
> push @ perl_files , $File::Find::name;
> }
> ===
>
>
>
>
> On Feb 22, 2006, at 9:10 PM, wrote:
>
>> Looks like what I needed (if works) but with a lot of editting: use
>> Module1,
>> use Module2, ..., use ModuleN.
>>
>>
>> Thanks.
>>
>> Harry
>>
>>
>>
>>
>> ----- Original Message -----
>> From: "Jonathan Vanasco"
>> To: "Harry Zhu"
>> Cc: "mod_perl List"
>> Sent: Wednesday, February 22, 2006 3:53 PM
>> Subject: Re: find all uninitialized variables?
>>
>>
>>> if you
>>> use strict ;
>>> use warnings;
>>>
>>> any module that you load w/an uninitialized variable will print an
>>> error
>>>
>>> what i do is as follows:
>>>
>>> use warnings & strict in $APP_DIR/etc/startup.pl
>>> include all my modules in $APP_DIR/etc/startup.pl
>>>
>>> tail -f $APP_DIR/logs/error.log
>>>
>>> sudo /usr/local/apache2/bin/apachectl restart
>>>
>>> that will try and include all the modules i listed in startup.pl
>>>
>>> if there's an uninitialized value, apache won't start up, and it will
>>> tell me the line.
>>> i fix that, and try to start apache again
>>>
>>> if you preload, you don't have to run through the pages - but it
>>> will crash on the first variable
>>>
>>>
>>> On Feb 22, 2006, at 6:37 PM, Harry Zhu wrote:
>>>
>>>> Say I have a file directory with hundreds of modules, I want to
>>>> know if there is a tool I can scan and identify the uninitalized
>>>> variables in all the files once (or through a loop) without
>>>> actually running through all the pages.
>>>>
>>>> Harry
>>>
>>>
>>
>>
>
>
>
>
> --
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.375 / Virus Database: 268.0.0/266 - Release Date: 2/21/2006
>
>

Re: find all uninitialized variables?

am 23.02.2006 03:10:42 von Harry Zhu

Looks like a cool QA tool, I'll check it out.
Thanks.

Harry

----- Original Message -----
From: "Tyler MacDonald"
To: "Harry Zhu"
Cc:
Sent: Wednesday, February 22, 2006 3:50 PM
Subject: Re: find all uninitialized variables?


> Harry Zhu wrote:
> > Say I have a file directory with hundreds of modules, I want to know if
> > there is a tool I can scan and identify the uninitalized variables in
all
> > the files once (or through a loop) without actually running through all
the
> > pages.
>
> If you don't want to run through all the pages and possibilites
> yourself, I reccommend selenium:
>
> http://www.openqa.org/selenium/
>
> That will allow you to create test suites that run in your browser
> that go through every page and try to do things on it. Then you can check
> your error logs and, if your test does everything a regular user possibly
> could, you'll have a list of all your uninitialized variables, as well as
> possibly turning up some bugs you hadn't tested for before.
>
> There's no easy way to do tell whether or not a variable is going to
> be used throughout the course of a webpage, except watching the warnings
and
> running every single code path that web page has (logged in, not logged
in,
> filled out this form element before hitting "submit", didn't, etc.)
>
> You might be able to do detect global variables that aren't used by
> a package, but nowadays over 90% of variables are local (my) variables,
and
> still... What if the variable isn't initialized in one module, because
> another module initializes it?
>
> Devel::Cover can help to see if you're running every single code
> path possible in the code you care about; Devel::Trace and Devel::Profile
> can help to see exactly what code you're actually running and when.
>
> If you just want to get rid of the warnings and don't care whether
> or not the module is using it's variables cleanly, you can add the line
>
> no warnings 'uninitalized';
>
> to each module that you're being annoyed by.
>
> - Tyler
>
>
>

Re: find all uninitialized variables?

am 23.02.2006 03:10:59 von Harry Zhu

Looks like what I needed (if works) but with a lot of editting: use Module1,
use Module2, ..., use ModuleN.


Thanks.

Harry




----- Original Message -----
From: "Jonathan Vanasco"
To: "Harry Zhu"
Cc: "mod_perl List"
Sent: Wednesday, February 22, 2006 3:53 PM
Subject: Re: find all uninitialized variables?


> if you
> use strict ;
> use warnings;
>
> any module that you load w/an uninitialized variable will print an error
>
> what i do is as follows:
>
> use warnings & strict in $APP_DIR/etc/startup.pl
> include all my modules in $APP_DIR/etc/startup.pl
>
> tail -f $APP_DIR/logs/error.log
>
> sudo /usr/local/apache2/bin/apachectl restart
>
> that will try and include all the modules i listed in startup.pl
>
> if there's an uninitialized value, apache won't start up, and it will
> tell me the line.
> i fix that, and try to start apache again
>
> if you preload, you don't have to run through the pages - but it
> will crash on the first variable
>
>
> On Feb 22, 2006, at 6:37 PM, Harry Zhu wrote:
>
> > Say I have a file directory with hundreds of modules, I want to
> > know if there is a tool I can scan and identify the uninitalized
> > variables in all the files once (or through a loop) without
> > actually running through all the pages.
> >
> > Harry
>
>

Re: find all uninitialized variables?

am 23.02.2006 04:52:31 von Ronald J Kimball

On Wed, Feb 22, 2006 at 03:47:45PM -0800, Ryan Gies wrote:
> 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...

The undef value *does* behave like zero or the empty string, as
appropriate. That's why you get a valid result, rather than an error or
undefined behavior. Nonetheless, it is uninitialized, so you also get a
warning.

Ronald

Re: find all uninitialized variables?

am 24.02.2006 12:12:00 von Konstantin Khomoutov

On Wed, Feb 22, 2006 at 06:10:59PM -0800, harry@greatlodge.com wrote:

> Looks like what I needed (if works) but with a lot of editting: use Module1,
> use Module2, ..., use ModuleN.
Why not just
$ find . -type f -name '*.pl' -print \
-exec perl -Mstrict -Mwarnings -c '{}' \; 2>&1 >error.log?

(Sorry, I'm on Windows now I can't check this, but you've got the
idea.)