Wagner, David --- Senior Programmer Analyst --- WGO wrote:
Daniel Kasak wrote:

Hi all.

I'm after people's thoughts on Perl's warnings about 'Use of
uninitialized value' in various situations ( string comparisons,
subroutine entries, etc ).
I understand what the warning is for.
In my code, it's perfectly OK for my variables to be uninitialised,
and is beyond my control anyway - the data is coming from a database,
and an undef value is perfectly legal ( NULL fields ).

I can make Perl stop complaining about it by placing if() statements
around everything, eg:


if you are using : use warnings;

Then you can use 'no warnings;' just like you would use 'use warnings' to turn off. Then you can use 'use warnings' to get it goint again. The better point might be to surround what you want within {}'s and use your 'no warnings' and once you hit the ending }, then will return to using warnings again.

You can be a little more specific with:

no warnings qw( uninitialized ); # see `perldoc perllexwarn`

You could also use a default value;

my $value = fetch_value() || '';

or what most seem to do is combine the tests:

if ( defined( $value ) && $value eq 'some_value' ) { ... }


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to