Kevin Old wrote:
>
> On Mon, 2003-11-24 at 13:30, Eric Walker wrote:
> > How can I test for empty strings and nulls on a particular value.   When
> > I get an empty string or a null value I need to do something.
>
> Hi Eric,
>
> To test for a empty string simply do the following:
>
> if ($mystring eq "") {
> #string is empty
> }

Yep.

> For a null or undefined value do:
>
> if($mystring) {
> #variable is undefined
> }

No. $mystring is true if is defined and is neither an
empty string nor zero.

> the long version is:
>
> if($mystring eq undef) {
> #variable is undefined
> }

No no no! Because of the string comparison this
will force 'undef' to an empty string and therefore
be the same as

  if ($mystring eq '')

What you mean here is

  if (not defined $mystring) {
    #variable is undefined
  }

Cheers Kevin.

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to