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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl -w
use strict;
use HTML::Template;
# open the html template
my $doc = <<ENDE
<TMPL_LOOP name="outer_loop">
<td>
<TMPL_VAR name="schluessel">
<TMPL_LOOP name="inner_loop">
<br /><TMPL_VAR name="daten">
</TMPL_LOOP>
</td>
</TMPL_LOOP>
ENDE
;
my $template = HTML::Template->new(scalarref => \$doc);
# Beispiedaten
my %thehash = (
Erster_Schluessel => [ 'a1', 'a2' ],
Zweiter_Schluessel => [ 'b1', 'b2', 'b3' ]
);
my (@outer_loop, @inner_loop, $schluessel, $daten);
foreach $schluessel (keys %thehash) {
my %outer_loop_row;
foreach my $daten (@{$thehash{$schluessel}}) {
my %inner_loop_row;
$inner_loop_row{"daten"} = $daten;
push (@inner_loop, \%inner_loop_row);
}
%outer_loop_row =(
schluessel => $schluessel,
inner_loop => \@inner_loop
);
push (@outer_loop, \%outer_loop_row);
}
$template->param(outer_loop => \@outer_loop);
print $template->output;
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
26
27
28
29
<td>
Erster_Schluessel
<br />a1
<br />a2
<br />b1
<br />b2
<br />b3
</td>
<td>
Zweiter_Schluessel
<br />a1
<br />a2
<br />b1
<br />b2
<br />b3
</td>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<td>
Erster_Name
<br />a1
<br />a2
</td>
<td>
Zweiter_Name
<br />b1
<br />b2
<br />b3
</td>
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl -w
use strict;
use HTML::Template;
# open the html template
my $doc = <<ENDE
<TMPL_LOOP name="outer_loop">
<td>
<TMPL_VAR name="schluessel">
<TMPL_LOOP name="inner_loop">
<br /><TMPL_VAR name="daten">
</TMPL_LOOP>
</td>
</TMPL_LOOP>
ENDE
;
my $template = HTML::Template->new(scalarref => \$doc);
# Beispiedaten
my %thehash = (
Erster_Schluessel => [ 'a1', 'a2' ],
Zweiter_Schluessel => [ 'b1', 'b2', 'b3' ]
);
foreach my $schluessel (keys %thehash) {
my (@outer_loop, @inner_loop, $daten);
my %outer_loop_row;
foreach my $daten (@{$thehash{$schluessel}}) {
my %inner_loop_row;
$inner_loop_row{"daten"} = $daten;
push (@inner_loop, \%inner_loop_row);
}
push (@outer_loop, \%outer_loop_row);
# %outer_loop_row =(
# schluessel => $schluessel,
# inner_loop => \@inner_loop
# );
$template->param(outer_loop =>
[ {
schluessel => $schluessel,
inner_loop => \@inner_loop
}
],
);
print $template->output;
}