Hello monks,

Can anyone tell me how to change a hash in order for it to be fed to a <TMPL_LOOP> within HTML::Template? Here is what I am doing:

$img_number = $1; $img_user = $2; $hash{$img_number} = $img_user;
This happens several times, and then I have a large hash. Do I need to put this into an array and assign it names? I tried the code below:
my @loop_data = (); push(@loop_data, \%hash); my $template = HTML::Template->new(filename => 'fun.tmpl'); my $CGI = CGI->new(); $template->param(template_loop => \@loop_data); print $CGI->header( ); print $CGI->title("Here is your output."); print $template->output; exit;
and it didn't work. It gave the following error:
HTML::Template->output() : fatal error in loop output : HTML::Template + : Attempt to set nonexistent parameter 'URL229' - this parameter nam +e doesn't match any declarations in the template file : (die_on_bad_p +arams => 1) at /usr/share/perl5/HTML/Template.pm line 2789 at /var/www/QQ/funtimes.pl line 171

I am sure that an array is involved, but I dont know how to go from a has to an array. Is this what is needed?

Thank you.


In reply to A hash to an array for HTML::Template by Anonymous Monk

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.