in reply to HTML::Template Interpolation Error?

checkbox_group returns a list! So what HTML::Template gets is:
$html->param( rcadd_list => "<input type=checkbox ...", "<input type=checkbox ..." => "<input type=checkbox ...", "<input type=checkbox ..." => ... );
This causes an HTML::Template error when die_on_bad_params is set. Either use join "" => checkbox_group(...) or force scalar context (with scalar or with concatenation as you did above) to get what you want.

blokhead

Replies are listed 'Best First'.
Re^2: HTML::Template Interpolation Error?
by hbo (Monk) on Aug 16, 2004 at 21:26 UTC
    Bingo, I think!

    So, why does ''.checkbox_group(.. flatten the list? Is

    "some string".('a','list','of','strings');
    equivilant to
    "some string".'a'.'list'.'of'.'strings';
    ?

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

      No, it's because the author of CGI.pm wrote it to do so:
      sub checkbox_group { ... return wantarray ? @elements : join(' ',@elements) ... }
      A list in scalar context (as in your example directly above) returns the last element of the list (your expression evaluates to "some stringstrings"). For a function, if you want different behavior (as in checkbox_group), you check for scalar or list context with wantarray and return the appropriate thing manually.

      The CGI docs could probably do a better job making this obvious, though. Perhaps there's a blanket statement somewhere about all HTML-generation functions having this behavior in scalar context?

      blokhead

        Got it.

        So the  ''.checkbox_group(... construct imposed scalar context, which returned something HTML::Template::param() could deal with.

        Thanks for the education!

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