Monks ~

I'm writing a script with CGI and HTML::Template. This code:

$template->param( STYLE_SHEET => "$STYLE_SHEET", SCRIPT_LOCATION => "$SCRIPT_LOCATION", MEMBER_NAME => $q->param('realname') );
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.

First question
This code:

$template->param( MEMBER_NAME => $q->param('realname') );
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.

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):

if (@row) { $q-param( mid => $row[0], name => $row[1], realname => $row[2], email => $row[3] ); }
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:
} else { $q-param( mid => 0, name => 0, realname => 0, email => 0 ); }
Surely there's a better way?

TIA
--
man with no legs, inc.


In reply to Odd (literally) problems with HTML::Template and params by legLess

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.