Leser: 19
1
2
3
4
Bereich| Jahr | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10| 11| 12|
==================================================================
Bereich1| 2010| 34 | 45 | 65 | | | 56| 45| | | | | |
Bereich2| 2010| 45 | 33 | | | | | | | | | | |
1
2
3
4
5
6
7
8
9
10
while DB-Record lesen {
$m[$monat] = $wert;
$rec = {}
rec->{key} = $bereich . $jahr;
$rec->{bereich} = $bereich;
$rec->{jahr} = $jahr;
$rec-{monate} = [ @m ];
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
my %sections; while (my $row = $sth->fetchrow_arrayref) { my ($section, $year, $month, $value) = @$row{qw/ Bereich Jahr Monat Wert /}; $sections{$section}->{$year}->{$month} = $value; } for my $section (sort keys %sections) { print "$section |"; my $years = $sections{$section}; for my $year (sort keys %$years) { print " $year|"; my $months = $years->{$year}; my @values = map { defined $months->{$_} ? $months->{$_} : "" } 1 .. 12; local $" = " | "; say "@values"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
my $kap = kapitel(); foreach (sort keys %$kap) { print %{$kap->{$_}->{name}}, "\n"; } sub kapitel { # Daten aus der DB Lesen while (my @row=$sth->fetchrow_array()){ $rec = {}; $rec->{key} = $row[0]; $rec->{name} = $row[1]; $rec->{sort} = $row[2]; $rec->{status} = $row[3]; $inRec{ $rec->{key} } = $rec; } return \%inRec; } # END kapitel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
sub kapitel { # Daten aus der DB Lesen while (my @row=$sth->fetchrow_array()){ my $key = $row[0]; $inRec{$key}->{key} = $key; $inRec{$key}->{name} = $row[1]; $inRec{$key}->{sort} = $row[2]; $inRec{$key}->{status} = $row[3]; } return \%inRec; } # END kapitel