[dancer-users] Only even items

David Precious davidp at preshweb.co.uk
Mon Apr 8 20:25:09 BST 2013


On Mon, 08 Apr 2013 19:44:24 +0200
Hugues Max <huguesmax at gmail.com> wrote:

> Hello
> I've got stange problem with dancer with twitter boostrap
> I use
> 
> use Dancer::Plugin::Database;
> my $dbh = database({driver => 'mysql', database => 'asav'});
>   my %allCommandeBNP = database->quick_select('CommandeBNP', {} );

The docs[0] say of quick_select:

 returns either the first matching row as a hashref if called in scalar
 context, or a list of matching rows as hashrefs if called in list
 context

You're assigning that to a hash; that implies list context, so your
hash will have both keys and values representing rows.

e.g. you'll end up with a hash looking like:

  (
      'HASH(0x5356)' => \%row1,
      'HASH(0x5367)' => \%row2,
  )

etc.

You want to assign straight to a list:

  my @allCommandeBNP = database->quick_select('CommandeBNP', {} );

Then pass that straight to your template, e.g.

  ccmd => \@allCommandeBNP,

And in your template, just iterate over that.


[0] https://metacpan.org/module/Dancer::Plugin::Database::Handle



-- 
David Precious ("bigpresh") <davidp at preshweb.co.uk>
http://www.preshweb.co.uk/     www.preshweb.co.uk/twitter
www.preshweb.co.uk/linkedin    www.preshweb.co.uk/facebook
www.preshweb.co.uk/cpan        www.preshweb.co.uk/github




More information about the dancer-users mailing list