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

Thank you. I figured it out, based on what you said. I had not checked to make sure a field was "defined" before I used it to do a if statement.

Now I am having to go through TONS of lines of different pages to see where else I did that :o(

Now I know. THANK YOU!

thx,
Richard

Replies are listed 'Best First'.
Re^3: Use of uninitialized value??
by Ionizor (Pilgrim) on Jan 28, 2003 at 08:25 UTC

    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.

      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 # ... }