What's happening is that param() isn't actually returning undef - it's returning an empty list. As it says in the documentation for CGI:
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:
my %hash = ( foo => 1, bar => 2, baz => (), qux => 3); print keys %hash;
What this means for you is that you need to call the param() method in scalar context. You can either do it directly:
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'), );
or you can try to get clever by doing something like this:
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;
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.

In reply to Re: Unexpected Hash Assignment using cgi->params by Errto
in thread Unexpected Hash Assignment using cgi->params by Pearte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.