Bob Showalter wrote:
> Siegfried Heintze wrote:
> > How do I distinguish between no value and false? I thought defined
> > was supposed to do that. 
> > 
> > So if I call $q->param("xyz"), how do I distinguish between
> > &xyz=0&abc and &xyz=&abc and xyz being absent all together?
> 
> param() will return undef in scalar context, or an empty list in list
> context if the parameter is totally absent.
> 
> So if the query string is 'xyz=0&abc', param('xyz') will return '0'.
> 
> If the query string is 'xyz=&abc', param('xyz') will return ''.
> 
> If the query string is 'abc=foo', param('xyz') will return undef (in
> scalar context)
> 
> So, you can do something like:
> 
>     my $xyz = param('xyz');
>     if (defined $xyz) {
>         print "parameter xyz was present. it's value is [$xyz]\n";
>     }

I should add that if this is coming from a form submission and they've left
the field blank, you can't test for that with defined(). You need to test
for whatever you consider a blank field to be.

I often do something like this:

   die "You must enter an id\n" unless $q->param('id') =~ /\S/;

That will die if they leave the field blank or just put whitespace in it.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to