The idea of using something like HTML::Template is definitely worth looking into -- it can simplify your perl code a lot, and make it easier to tweak/fix the HTML display without having to change the perl code.

Based on the code you've posted, it's not clear to me (because I lack CSS experience) how the div and br tags are being transformed into a table layout. In any case, if I were to try to do this without HTML::Template, it would probably look something like this (note that I'm not using div or br tags, either, but maybe you can work that out yourself, if it matters):

# create a reference to a hash with @$times as keys and values: my $times_href = { map { $_ => $_ } @$times }; # add the image tagging to the $icon elements: $icons->{$_} = "<img src=\"$icons->{$_}\" alt=\"\" />" for ( keys %$ic +ons ); print "<table>\n"; for my $dref ( $icons, $times_href, $conditions, $hilo, $temperatures +) { print "<tr>"; print "<td>$dref->{$_}</td>" for ( @$times ); print "</tr>\n"; } print "</table>\n";
(not tested)

Since most of your data is in hash refs already, putting the @$times data into a hash ref as well means that you can treat all the table rows the same way, and you still use @$times to run the loop that prints the columns on each row in the proper order.

(updated to add (and fix) the for loop that modifies the contents of the $icons hash ref, so that they can also be used the same way as the other hash refs when printing the table)

(another update: I realize that I've left out some of the details in the OP code, like adding the "°F" on the temperatures, the "abbr" tags, etc. But these would be handled the same way as adding the "img" tagging on the "%$icons" data.)


In reply to Re: For statement 2 html table by graff
in thread For statement 2 html table by senik148

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.