in reply to Strange behaviour - cgi related

It's because you're calling param() in a list context, so for the non-existent parameter you get an empty list. It's just as if you had done

my %hash = ( 'foo' => (), 'bar' => 'baz' ); # which is the same as ... my %hash = ( 'foo', 'bar', 'baz' );

Replies are listed 'Best First'.
Re: Re: Strange behaviour - cgi related
by kiat (Vicar) on Dec 16, 2003 at 04:46 UTC
    Thanks, duff!

    Just to clarify

    my $in = param('place'), my $place = seewhatsthere( data => $in, field => 'Place', );
    Is that correct way to pass the value from the checkbox?

      That's a way. The key is to not use param() in a list context. You can force scalar context as you have done (by assigning to a scalar) or you can use the scalar operator like so:

      my %hash = ( data => scalar param('place'), field => 'place', );
        I see. I don't seem to have that problem when the param value is from a input field of type 'text' or type 'password'. To make my question more concrete, here's an example
        # html <tr><td>Username<td><td><input type="text" name="username" size="25">< +/td></tr> # cgi my $username = seewhatsthere( data => param('username'), field => 'Username', ); sub seewhatsthere { my %hash = @_; html_start(); print Dumper(%hash); exit(0); } # Dumped $VAR1 = 'data'; $VAR2 = ''; $VAR3 = 'field'; $VAR4 = 'Username';
        In the above case, even though the username is not filled, the dumped output is as expected. Which means that if the input type is 'text', passing param() to a list is permissible ( as shown in the code ). Am I getting it right?