Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: perl CGI form ignores value

by rjt (Deacon)
on Sep 17, 2012 at 03:10 UTC ( #993948=note: print w/replies, xml ) Need Help??


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;

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993948]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2016-09-27 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (516 votes). Check out past polls.