Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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;


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

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 having an uproarious good time at the Monastery: (7)
As of 2014-08-23 15:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (174 votes), past polls