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? | [reply] [d/l] |
I was going to just point you at the documentation, but when I looked it didn't seem to be clearly stated. It's only when the parameter may be multivalued that you have to worry about list vs. scalar context. For single valued parameters, you always only get a scalar. The docs for CGI actually say ... Pass the param() method a single argument to fetch the value of the named parameter. If the parameter is multivalued (e.g. from multiple selections in a scrolling list), you can ask to receive an array. Otherwise the method will return a single value. Something more akin to "If the parameter is multivalued, you will get a list in list context and a scalar in scalar context" is more accurate.
| [reply] |