vielleicht mit line-numbers besser :)
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
49
50
51
52
53
1 #!/usr/bin/perl -w
2
3 use CGI;
4 use CGI::Carp qw(fatalsToBrowser);
5 use HTML::Template;
6 use strict;
7
8 my $template = HTML::Template->new(filename => '1.tmpl');
9 my $cgi = CGI->new();
10
11
12 sub build_selectbox
13 {
14 my ($loop_name, $selected_var, @a_selectbox_values) = @_;
15
16 my ($i, $selected, @a_selectbox_loop);
17
18 if (!defined($selected_var))
19 {
20 $selected_var = 1;
21 }
22
23 for(@a_selectbox_values)
24 {
25 $selected=0;
26
27 if ($i == $selected_var)
28 {
29 $selected=1;
30 }
31
32 push(@a_selectbox_loop,{
33 selectbox_label => $a_selectbox_values[$i],
34 selectbox_value => $i,
35 selectbox_selected => $selected
36 });
37 $i++;
38 }
39
40 $template->param({$loop_name => \@a_selectbox_loop});
41 }
42
43
44 my @a_array = ('---','Berlin','Wien','Bern');
45 &build_selectbox('loop_kursort', 2, @a_array);
46
47 #<select name="kursort">
48 # <!-- TMPL_LOOP NAME="loop_kursort">
49 # <option value="<!-- TMPL_VAR NAME="selectbox_value"-->"<!-- TMPL_IF NAME="selectbox_selected"--> selected<!-- /TMPL_IF-->> <!-- TMPL_VAR NAME="selectbox_label"--> </option>
50 #<!-- /TMPL_LOOP-->
51 #</select>
52
53 print $template->output;