Some code I wrote came back to me today with the complaint that it was blowing up with an error:
The code in question looked like this:HTML::Template : Attempt to set nonexistent parameter '<input type="ch +eckbox" ...
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.$html->param('rcadd_list' => ''.checkbox_group( ...
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
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.'rcadd_list' => <input type="checkbox ..>
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:
Which makes the whole thing more explicit, in case anyone as thick as I comes along to work on this in the future. 8)# We need to force scalar context because # checkbox_group() returns a list, otherwise. $html->param(rcadd_list => scalar ( checkbox_group( ...
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |