This is my best guess at what your source data is and how to process it.
poj#!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>
In reply to Re^5: HTML::Template question
by poj
in thread HTML::Template question
by iRemix94
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |