#!/usr/bin/perl -w use CGI; use CGI::Carp qw(fatalsToBrowser); use HTML::Template; use strict; my $template = HTML::Template->new(filename => '1.tmpl'); my $cgi = CGI->new(); sub build_selectbox { my ($loop_name, $selected_var, @a_selectbox_values) = @_; my ($i, $selected, @a_selectbox_loop); if (!defined($selected_var)) { $selected_var = 1; } for(@a_selectbox_values) { $selected=0; if ($i == $selected_var) { $selected=1; } push(@a_selectbox_loop,{ selectbox_label => $a_selectbox_values[$i], selectbox_value => $i, selectbox_selected => $selected }); $i++; } $template->param({$loop_name => \@a_selectbox_loop}); } my @a_array = ('---','Berlin','Wien','Bern'); &build_selectbox('loop_kursort', 2, @a_array); print $template->output;