legLess has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a script with CGI and HTML::Template. This code:
Produces an error ("You gave me an odd number of parameters to param()!") if $q->param('realname') isn't defined. Set $q->param('realname') to 0 (or anything else) and everything's fine.$template->param( STYLE_SHEET => "$STYLE_SHEET", SCRIPT_LOCATION => "$SCRIPT_LOCATION", MEMBER_NAME => $q->param('realname') );
First question
This code:
Produces no errors with identical input. Why? As long as MEMBER_NAME is the only parameter, it seems not to matter if $q->param('realname') defined or not. It's only when there are other parameters that I get the error. The error itself makes a sort of sense, but this seems inconsistent.$template->param( MEMBER_NAME => $q->param('realname') );
Second question
One solution to this is to explicitly set every parameter to 0 if it's not defined. This is possible, but inelegant, and a headache. I like that Perl assumes false if something's undefined. Am I missing something?
Third question
This code is kind of ugly, especially compared with assigning to a hash slice (@row is a row returned from a database):
And if, as in question 2 above, I set every param to 0 if it was undefined, I'd have to add something like this:if (@row) { $q-param( mid => $row[0], name => $row[1], realname => $row[2], email => $row[3] ); }
Surely there's a better way?} else { $q-param( mid => 0, name => 0, realname => 0, email => 0 ); }
TIA
--
man with no legs, inc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Odd (literally) problems with HTML::Template and params
by bikeNomad (Priest) on Jul 10, 2001 at 08:02 UTC | |
by legLess (Hermit) on Jul 10, 2001 at 22:16 UTC | |
|
Re: Odd (literally) problems with HTML::Template and params
by LD2 (Curate) on Jul 10, 2001 at 08:43 UTC | |
|
Re: Odd (literally) problems with HTML::Template and params
by bwana147 (Pilgrim) on Jul 10, 2001 at 10:59 UTC | |
by legLess (Hermit) on Jul 10, 2001 at 22:15 UTC | |
|
Re: Odd (literally) problems with HTML::Template and params
by PrakashK (Pilgrim) on Jul 10, 2001 at 08:41 UTC | |
by legLess (Hermit) on Jul 10, 2001 at 22:15 UTC |