Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:

Hey everyone,

I'm just trying to figure out what im doing wrong here with my syntax. All my values are returning "undef" when I call them. Can i get a second pair of eyes? Or perhaps more? :)

Thanks in advanced. The Code Snippet:
foreach my $emp_count (1 .. 3) { push @emp, { "employer" => $q->param("employer$emp_count"), "street" => $q->param("street$emp_count"), "city" => $q->param("city$emp_count"), "state" => $q->param("state$emp_count"), "zip" => $q->param("zip$emp_count"), "phone" => $q->param("phone$emp_count"), "startdate" => $q->param("StartMonth$emp_count") . "/" + . param("StartYear$emp_count"), "enddate" => $q->param("EndMonth$emp_count") . "/" . p +aram("EndYear$emp_count"), "startpay" => $q->param("startpay$emp_count"), "finalpay" => $q->param("finalpay$emp_count"), "reason" => $q->param("reason$emp_count"), "contact" => $q->param("contact$emp_count"), "jobtitle" => $q->param("jobtitle$emp_count"), "supervisor" => $q->param("supervisor$emp_count"), "sjobtitle" => $q->param("sjobtitle$emp_count"), "work" => $q->param("work$emp_count"), } }
All values are = undef Here is how I'm calling the values: $emp[$emp_in_count]->{'city'}

Replies are listed 'Best First'.
Re: Undef Hash/Scalar Problem
by chromatic (Archbishop) on Mar 10, 2008 at 19:25 UTC

    Assignment to a hash is in list context, so almost all of those param() method calls are in list context. Do you know what that method returns in list context?

    Besides that, you're mixing method calls with function calls. That's generally a very bad idea.

    Everything should be $q->param( ... ), and you should prefix all of those with scalar.

    push @emp, { "employer" => scalar $q->param("employer$emp_count"), "street" => scalar $q->param("street$emp_count"), ... };
Re: Undef Hash/Scalar Problem
by hipowls (Curate) on Mar 10, 2008 at 20:32 UTC

    Chomatic is probably correct, you are not creating the data you think you are. To see what the data structure actually is use Data::Dumper or YAML to print it out.

    use DATA::Dumper; ... print Dumper \@emp;
    or
    use YAML; ... print Dump \@emp;
Re: Undef Hash/Scalar Problem
by ysth (Canon) on Mar 11, 2008 at 00:49 UTC
    Is this some kind of test to see if you get the same answers here as in the chatterbox? If so, we passed. :)

    One more thing (in addition to the above suggestions, not something to hare off after instead of the above fix/check): make sure $emp_in_count is what you think it is.