#!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 days } }, }, '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 days } } }, }, ); 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_columns_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__