Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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 drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2014-09-16 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls