Greets.

Some code I wrote came back to me today with the complaint that it was blowing up with an error:

HTML::Template : Attempt to set nonexistent parameter '<input type="ch +eckbox" ...
The code in question looked like this:
$html->param('rcadd_list' => checkbox_group( ...
So it looks like the 'rcadd_list' parameter is getting swallowed. To make a long story short, changing the code like this:
$html->param('rcadd_list' => ''.checkbox_group( ...
Fixed it up.

I'm relying on interpolating the return value of a CGI call into the parameter list of an HTML::Template call throughout this code, not to mention throughout my career. Why does it fail in this case?

Update:

blokhead supplied my answer.

checkbox_group() returns a list in list context. HTML::Template::param takes a list of key/value pairs. The first pair was thus

'rcadd_list' => <input type="checkbox ..>
where the second parameter is the first <input> tag returned by the checkbox_group call. But then the next <input> tag becomes a parameter tag for HTML::Template::param(), which is totally fubar.

Prepending an empty string as above forced scalar context, which made checkbox_group return a space-seperated list of input tags, which was just what I wanted. I ended up changing the code like so:

# We need to force scalar context because # checkbox_group() returns a list, otherwise. $html->param(rcadd_list => scalar ( checkbox_group( ...
Which makes the whole thing more explicit, in case anyone as thick as I comes along to work on this in the future. 8)

Thanks to blokhead for the correct answer!

"Even if you are on the right track, you'll get run over if you just sit there." - Will Rogers


In reply to HTML::Template Interpolation Error? by hbo

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.