in reply to Re: Re: Use of uninitialized value??
in thread Use of uninitialized value??

Keep in mind that the "Use of uninitialized..." message is only a warning. Strictly speaking you don't have to fix it but naturally it's best to do so.

The way I commonly fix this is to do:

if ($variable and $variable eq 'value') { # do something # ... }

This uses the "short circuit" property of and to check whether the variable is defined before it checks the value. I'm sure some of the more experienced monks can enlighten us as to whether or not this is good practice.

--
Grant me the wisdom to shut my mouth when I don't know what I'm talking about.

Replies are listed 'Best First'.
Re^4: Use of uninitialized value??
by Anonymous Monk on Mar 30, 2006 at 05:38 UTC
    Whatch out for:
    if ($variable and $variable eq 'value') { # do something # ... }
    as you are testing not only that the value is defined, but that the value is also not zero or an empty string. As a general practice, you should be writing:
    if ((defined $variable) && ($variable eq 'value')) { # do something # ... }