Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
If you are going to address columns by name, (author, title, language, format, etc), you might want to get your database results as an array of hashes. DBI recipes is a good start here.

The little program I wrote returns all rows as an array of hashes. The text after the __END__ token shows a select * from the command line, (to show the contents of the id_minutes table).

The text after the sqlite result is the Data::Dumper output of the array of hashes.

#!/usr/bin/perl use strict; use warnings; use DBI; use Data::Dumper; # my $dbh = DBI->connect("dbi:SQLite:dbname=junk.lite","","", {PrintError => 1}) or die "Can't connect"; my $query = q{SELECT * FROM id_minutes}; my $aref = $dbh->selectall_arrayref($query, { Slice => {} }); $dbh->disconnect or die $dbh->errstr; print Dumper $aref; __END__ C:\Old_Data\perlp>sqlite3 junk.lite SQLite version 3.7.3 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite> .mode column sqlite> .width 10 10 10 sqlite> .head on sqlite> select * from id_minutes; id month minutes ---------- ---------- ---------- maclaw796 Oct 6 hturner Oct 53 nnt Oct 3 sqlite> C:\Old_Data\perlp>perl $VAR1 = [ { 'month' => 'Oct', 'minutes' => 6, 'id' => 'maclaw796' }, { 'month' => 'Oct', 'minutes' => 53, 'id' => 'hturner' }, { 'month' => 'Oct', 'minutes' => 3, 'id' => 'nnt' } ]; C:\Old_Data\perlp>

In reply to Re: multidimensional array's by Cristoforo
in thread multidimensional array's by emgi

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (4)
    As of 2018-06-18 00:46 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (107 votes). Check out past polls.