in reply to Unexpected Hash Assignment using cgi->params
If the parameter does not exist at all, then param() will return undef in a scalar context, and the empty list in a list context.So your keys and values get offset by one. Try this little example for an illustration of the effect of this:
What this means for you is that you need to call the param() method in scalar context. You can either do it directly:my %hash = ( foo => 1, bar => 2, baz => (), qux => 3); print keys %hash;
or you can try to get clever by doing something like this:my %data = ( 'email'=>scalar $cgi->param('user_email'), 'name'=>scalar $cgi->param('user_name'), 'cell_phone'=>scalar $cgi->param('user_cell_phone'), 'home_phone'=>scalar $cgi->param('user_home_phone'), 'work_phone'=>scalar $cgi->param('user_work_phone'), );
This takes advantage of the fact that you can modify hash values in place. Also, the scalar context is automatic because it's an assignment to a scalar value, so you don't need to specify it.my %data = ('email' => 'user_email', 'name' => 'user_name', 'cell_phone' => 'user_cell_phone', 'home_phone' => 'user_h +ome_phone', 'work_phone' => 'user_work_phone'); $_ = $cgi->param($_) for values %data;
|
|---|