in reply to Check Variables for NULL

sorry I didnt give enough information apparently.

Basically i perl script that pulls in data from the user. But I'm trying to write and if statement that will say something like "Hey, you didnt put any data in that box!" So I want to check if the $value is "0" or "blank" give the error, if it has data run the rest of the script.

Replies are listed 'Best First'.
Re^2: Check Variables for NULL
by Joost (Canon) on Feb 07, 2007 at 21:22 UTC
    Well the answer depends on how you get the value from the "box". Most UI components return empty input as an empty string, but some might return undef instead.

    # let's say you've got the user input in $input.. if (defined($input) && $input ne "") { # input is defined and not empty } else { print "input wasn't filled in\n"; }
    Note that compare strings with eq and ne instead of == and != since == and != coerce their arguments to numbers.

    See equality operators and defined in the documentation.

      Your awesome!!
      Thanks so much for your help, for some reason I just forgot about "EQ and NE"
      Duh!
        for some reason I just forgot about "EQ and NE"
        It would be good to keep brush up your knowledge in perl.
        Note that uppercase "EQ" and "NE" are deprecated and might go away sometime. Use "eq" and "ne" instead.