[dancer-users] Getting Value of nested hash attributes -- HASH confusion

Andrew Beverley andy at andybev.com
Mon Aug 31 23:07:44 BST 2015

On Mon, 2015-08-31 at 16:37 -0500, Richard Reina wrote:
>                   <td width="550"><% Chlngs.$ID.DESCRIP %></td>
>                   <td><input type="text" name="<% Chlngs.$ID.ID %>"

So, the name of the input parameter is an ID number.

> However, after getting the template to work I am once again stumped in how
> to capture the value of the dynamically named hash ref

In which case it will be returned as a scalar using param():

    my $value = param( $key );

Which will return, for example, "7", if that is what is in the textbox.

>     foreach my $key ( keys %$Chlngs ) {
>       print "Checking Chlgs: " . $key . " for value.\n";
>       if ( param( $key ) ) { # paramter has value
>           #$input_hash->{ $key } = $Chlngs->{ $key };
>           $input_hash->{ $key } = param( $key );

               ^^ So just capture the value here, but just in a scalar
Is there a reason for using a hash?

>           #print $key, $input_hash->{ $key }, "\n";
>           #print %{ $input_hash->{1} };
>           print $input_hash->{1}{ID}, "\n";
>               # $sth->execute($PLR_ID, $key, $input_hash->{Season},
> $input_hash->{Year}, $input_hash->{CharID});

                ^^ And update it here

But I'm not quite sure why you are also updating the other values? Where are they
coming from? If they haven't changed, then don't bother passing them into the SQL
query, just do an execute on the captured value.

More information about the dancer-users mailing list