in reply to Filling Table in a HTML file using perl

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