----- Original Message ----- 
From: Paul <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; Perl Discuss <[EMAIL PROTECTED]>
Sent: Monday, June 04, 2001 8:51 PM
Subject: Re: testing null strings for form field values


> 
> --- [EMAIL PROTECTED] wrote:
> > if ( $formdata{view_name} ne "" ) {
> >   $view = $formdata{view_name};
> >   $viewtag = "1";
> > }
> 
> For a simple boolean test, I usually find it more readable to be less
> explicit in these cases:
> 
>   if ( $formdata{view_name} ) {
>      # etc.
>   }

I think this will return false when a numeric zero is entered in the input.
Some weeks before there was a similiar question...
You could use defined(), but that would allow an empty string.
So actually you should test against both: 

if ( defined $formdata{view_name} && $formdata{view_name} ne "" ) {...}

which is rather long.

>From the previous discussion the following nice alternative came up:

 if ( length($formdata{view_name}) ) {...}

which does a nice job and is pretty readable.

Maarten.

Reply via email to