This is my best guess at what your source data is and how to process it.

#!perl use strict; use HTML::Template; use Data::Dump 'pp'; my %bi = ( 'Customer 1'=>{ 'Domain 1'=>{ 'Host 1'=>{ BACKUPCFG=>{ EXPORT_SCHEDULE_1=>{ VALUE => '01:00,02:00,03:00' }, IMPORT_ACTIVE_1=>{ VALUE => 1 }, EXPORT_ACTIVE_1=>{ VALUE => 1 }, EXPORT_BACKUP_LIFETIME_SEC_1=>{ VALUE => 3600*24*3 }, # 3 da +ys } }, }, 'Domain 2'=>{ 'Host 2'=>{ BACKUPCFG=>{ EXPORT_SCHEDULE_1=>{ VALUE => '05:00,06:00,07:00,08:00' }, IMPORT_ACTIVE_1=>{ VALUE => 1 }, EXPORT_ACTIVE_1=>{ VALUE => 1 }, EXPORT_BACKUP_LIFETIME_SEC_1=>{ VALUE => 3600*24*4 }, # 4 da +ys } } }, }, ); my $customer = "Customer 1"; my $tr_bgcolor = '#0000ff'; my @data_structure_loop = (); for my $domain (sort keys %{$bi{$customer}}) { my @schedule_rows_loop=(); my %data = ( CUSTOMER => $customer, DOMAIN => $domain, ); my @hosts = sort keys %{$bi{$customer}{$domain}}; for my $host (@hosts) { my $hr = $bi{$customer}{$domain}{$host}->{BACKUPCFG}; my $schedule = $hr->{EXPORT_SCHEDULE_1}->{VALUE}; if (defined $schedule){ ## Da nicht alle Kunden / Domainen zurzeit eine EXPORT_SCHEDULE +haben $data{IMPORT_VALUE} = $hr->{IMPORT_ACTIVE_1}->{VALUE}; $data{EXPORT_VALUE} = $hr->{EXPORT_ACTIVE_1}->{VALUE}; my $t = $hr->{EXPORT_BACKUP_LIFETIME_SEC_1}->{VALUE}; my $scheduled_export_days = convert_seconds_days($t); my @schedule = split /,/, $schedule; for my $dif_schedule (@schedule) { my @schedule_columns_loop = (); for my $i (0..$scheduled_export_days){ push @schedule_columns_loop, {SCHEDULE => $dif_schedule}; } push @schedule_rows_loop, {SCHEDULE_COLUMNS => \@schedule_colu +mns_loop }; } } } $data{BGCOLOR_CUSTOMER} = $tr_bgcolor; $data{SCHEDULE_ROWS} = \@schedule_rows_loop; push @data_structure_loop, \%data; #pp \%data; } my $template = HTML::Template->new_filehandle(\*DATA); $template->param(DATA_STRUCTURE => \@data_structure_loop); open HTM,'>','test.htm' or die "$!"; print HTM $template->output; sub convert_seconds_days { my $s = shift; return int $s/(3600*24); } __DATA__ <html> <head></head> <body> <table border="1" cellpadding="3" cellspacing="0"> <TMPL_LOOP NAME=DATA_STRUCTURE> <TMPL_IF NAME=BGCOLOR_CUSTOMER> <tr> <TMPL_ELSE> <tr bgcolor="white"> </TMPL_IF> <th><TMPL_VAR NAME=CUSTOMER></th> <th><TMPL_VAR NAME=DOMAIN></th> <td> <TMPL_IF NAME=EXPORT_VALUE> <table border="1" cellpadding="3" cellspacing="0"> <TMPL_LOOP NAME=SCHEDULE_ROWS> <tr> <TMPL_LOOP NAME=SCHEDULE_COLUMNS> <td><b><TMPL_VAR NAME=SCHEDULE></b></td> </TMPL_LOOP> </tr> </TMPL_LOOP> </table> </TMPL_IF> </td> <td> <TMPL_IF NAME=IMPORT_VALUE> <table border="1" cellpadding="3" cellspacing="0"> <TMPL_LOOP NAME=SCHEDULE_ROWS> <tr> <TMPL_LOOP NAME=SCHEDULE_COLUMNS> <td><b><TMPL_VAR NAME=SCHEDULE></b></td> </TMPL_LOOP> </tr> </TMPL_LOOP> </table> </td> </TMPL_IF> </tr> </TMPL_LOOP> </table> </body> </html>
poj

In reply to Re^5: HTML::Template question by poj
in thread HTML::Template question by iRemix94

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.