Hi,
I have the following problem:
I have a CGI script that reads data from a text file and sends it to HTML::Template in TMPL_LOOP. Every row in that file has a key and value pair. Here is a part from that script:
foreach $line (@lines) { ($name, $value) = split(/=/, $line); chomp($name); chomp($value); if ($name eq "loop" and $value eq "start") { $loop_status = "start"; } if ($loop_status eq "start") { if ($name eq "loop_name") { $loop_name = $value; } elsif ($name eq "loop" and $value eq "end") { $loop_status = "end"; $template->param(eval "$loop_name" => \@loop); } elsif ($name eq "row" and $value eq "start") { my %row; } elsif ($name eq "row" and $value eq "end") { push (@loop, \%row); } else { if ($name ne "loop") { $row{eval "$name"} = $value; } } } if ($loop_status ne "start") { if ($name ne "loop" and $name ne "loop_name" and $name ne "row" an +d $name { $template->param($name, $value); } } }
But it doesn't work what I expect. I get all rows with the same values as in the last row read from the text file. This is what I get when I check the @loop array:
$VAR1 = [ { 'rel_date' => '04/060/09', 'importer' => 'Something', 'file_id' => '123', 'vendor' => 'Some', 'urgency' => '5' }, $VAR1->[0], $VAR1->[0], $VAR1->[0], $VAR1->[0] ];
It seems that it does not create new hash %row when it goes through the loop.

Any suggestions?
Thanks


In reply to adding a new hash in an array by popsin

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.