Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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;

Comment on Re: perl CGI form ignores value
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2015-10-10 08:05 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (255 votes), past polls