G'day farha89,

You don't show the source of the data nor the data structure you've used nor the code you've written to create and populate that structure. I suggest the following and leave the coding to you:

{ name => { stage0 => [old, new], ..., stageN => [old, new], }, ..., }

Using that structure, generating the HTML is straightforward (I've only shown the <table>...</table> part):

#!/usr/bin/env perl use strict; use warnings; my %data = ( tony => { skill => [ 1, 1 ], skill1 => [ 0, 0 ], }, martin => { skill => [ 1, 0 ], }, ); print qq{<table border="1" cellpadding="2" cellspacing="0">\n}; print "<tr> <th>Name</th> <th>Stage</th> <th>Old</th> <th>New</th> </tr>\n"; for my $name (sort keys %data) { print "<tr>\n"; my $rowspan = keys %{$data{$name}}; print qq{ <td rowspan="$rowspan">\u$name</td>\n}; for my $stage (sort keys %{$data{$name}}) { print " <td>$stage</td>\n"; for (@{$data{$name}{$stage}}) { my $bool = $_ ? 'True' : 'False'; print " <td>$bool</td>\n"; } --$rowspan && print "</tr>\n<tr>\n"; } print "</tr>\n"; } print "</table>\n";

Output:

<table border="1" cellpadding="2" cellspacing="0"> <tr> <th>Name</th> <th>Stage</th> <th>Old</th> <th>New</th> </tr> <tr> <td rowspan="1">Martin</td> <td>skill</td> <td>True</td> <td>False</td> </tr> <tr> <td rowspan="2">Tony</td> <td>skill</td> <td>True</td> <td>True</td> </tr> <tr> <td>skill1</td> <td>False</td> <td>False</td> </tr> </table>

Which renders like this:

Name Stage Old New
Martin skill True False
Tony skill True True
skill1 False False

-- Ken


In reply to Re: Filling Table in a HTML file using perl by kcott
in thread Filling Table in a HTML file using perl by farha89

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.