in reply to perl CGI form ignores value
There are several ways you can do this, but the following is reasonably efficient, and hopefully your parameter list is relatively small anyway:
my $q = new CGI; my %vars = $q->Vars; # Fetch all CGI parameters my %db_vars = pop_defaults(); # Fetch from database # Override defined values from database $vars{$_} = $db_vars{$_} for (keys %db_vars); # Fetch all defaults from the DB and return as a hash ref sub pop_defaults { my $r = { }; ... return $r }
You can also simply loop through the params:
$vars{$_} = $db_vars{$_} // $q->param($_) for ($q->param);
Finally, if you prefer to merge hash slices:
%vars{keys %db_vars} = values %db_vars;
|
|---|