Thread Datenstruktur (4 answers)
Opened by tcicit at 2010-11-15 11:32

pq
 2010-11-15 11:57
#142757 #142757
User since
2003-08-04
12208 Artikel
Admin1
[Homepage]
user image
also wie gut kennst du dich denn schon mit datenstrukturen in perl aus?
http://p3rl.org/perldata
http://p3rl.org/perldsc
http://p3rl.org/perllol
http://p3rl.org/perlreftut

ich würde das in etwa so machen:
Code (perl): (dl )
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";
    }
}

evtl. noch ein bisschen feintuning bei der ausgabe.
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Datenstruktur