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

Richard Reina gatorreina at gmail.com
Mon Aug 31 22:37:21 BST 2015

I have to following template that lists table data with a checkbox to the
left and a text area to the right -- special thanks to Andrew for helping
me figure out the HTML.

The data comes from:

    my $q = "SELECT c.ID AS ID, u.screenname AS SNAME, a.name AS ANAME,
a.descrip AS DESCRIP,
                c.season AS SSN, c.year AS YR, ch.name AS CHNAME
                FROM challenge c, accomp_type a, usuario u, jugador j,
charity ch
                WHERE c.ACC_TYPE_ID=a.ID
                AND ch.ID=c.CHAR_ID
                AND c.PLR_ID=j.ID
                AND j.USER_ID=u.ID";
my $Chlngs = $dbh->selectall_hashref( $q, 'ID' );

<div class="container" style="margin-top:20px;">
  <div class="row">
    <div class="col-xs-12">
          <form role="form" action="openchallenges" method="POST">
            <h3 class="text-center">Open To Do</h3>
            <div class="well" style="max-height: 300px;overflow: auto;">
                <ul class="list-group fancy-list-items">    <!-- <ul
class="list-group checked-list-box"> -->
             <table style="width:100%">
                <% FOREACH ID IN Chlngs.keys.sort %>
                <tr class="list-group-item">
                 <td width="5"> <input type="checkbox" name="<% Chlngs.$
ID.NAME %>"</input> </td>
                  <td width="70"><% Chlngs.$ID.SNAME %></td>
                  <td width="75"><% Chlngs.$ID.ANAME %></td>
                  <td width="35"><% Chlngs.$ID.SSN %></td>
                  <td width="35"><% Chlngs.$ID.YR %></td>
                  <td width="250"><% Chlngs.$ID.CHNAME %></td>
                  <td width="550"><% Chlngs.$ID.DESCRIP %></td>
                  <td><input type="text" name="<% Chlngs.$ID.ID %>"
size="8" </td>
                  <% END %>
    <hr class="colorgraph">
    <div class="row">
    <div class="col-xs-12 col-md-12"><input type="submit" value="Submit"
class="btn btn-primary btn-block btn-lg"></div>

However, after getting the template to work I am once again stumped in how
to capture the value of the dynamically named hash ref -- specifically the
second one from the text box. I have tried various permutations below --
some of which were very graciously provided to me in an earlier similar
thread -- but all seem to only give me either a hash reference, the value
of ID or this error when I place the number 7 into the text field: Can't
use string ("7") as a HASH ref while "strict refs" in use at
/home/richard/Dancer2/MyApp/bin/../lib/MyApp.pm line 463.

my $input_hash;

    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 );
          #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});


Thanks for any help.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150831/379c9025/attachment.html>

More information about the dancer-users mailing list