On a side note, might I suggest using the CGI module or similar to output HTML, instead of printing it yourself. It will probably make things a lot simpler. Here is an sample of your code rewritten using CGI (plus a few style changes):
use CGI qw(:standard); # use functions instead of OO interface
sub build_select_field_from_db {
# --------------------------------------------------------
# Builds a SELECT field from the database.
my ( $column, $value, $name ) = @_;
my ( $fieldnum, $found ) = ( 0, 0 );
for my $i (0 .. $#db_cols) {
if ($column eq $db_cols[$i]) {
$fieldnum = $i; $found = 1;
last;
}
}
if (!$found) {
return q(error building select field: no fields specified!);
}
open my $DB, q(<), $db_file_name or cgierr(qq(unable to open $db_f
+ile_name. Reason: $!));
my @lines = <$DB>;
close $DB;
my @selectfields;
LINE: foreach my $line (@lines) {
if ($line =~ /^#/) { next LINE; } # Skip comment lines.
if ($line =~ /^\s*$/) { next LINE; } # Skip Blank Lines.
chomp $line;
my @fields = split_decode ($line);
if(!(List::MoreUtils::any { $_ eq $fields[$fieldnum] } @select
+fields)){
push @selectfields, $fields[$fieldnum];
}
}
my $output = popup_menu(
-name => defined $name ? $name : $column,
-values => [ '---', sort @selectfields ],
-default => $value,
);
return $output;
}