Slightly [OT]...

my @names = $db->query('SELECT name FROM people WHERE id > 5')->flat;

I thought that looked nice so I had a look at it. But when compared to the 'normal' DBI way it turns out there is really not much of an advantage. The line is a little shorter (++) but you get a dependency (--) and lose quite a bit of speed (--).

perl -MData::Dumper -MDBI -MDBIx::Simple -e ' my $db1 = DBI->connect; # (uses defaults to connect) my $db2 = DBIx::Simple->connect; use Benchmark qw( cmpthese ) ; my $COUNT = -20; print "-- COUNT [$COUNT]\n"; cmpthese( $COUNT, { selectrow_arrayref => sub { my @arr = @{ $db1->selectrow_arrayref( + "select i from generate_series(1,10) as f(i) where i > 5" ) }; }, dbix_query_flat => sub { my @arr = $db2->query( "select i from +generate_series(1,10) as f(i) where i > 5")->flat; }, }); ' -- COUNT [-20] Rate dbix_query_flat selectrow_arrayref dbix_query_flat 5608/s -- -23% selectrow_arrayref 7293/s 30% --

As always when I look closer at ORMy things (mainly because many people seem to be fond of ORMs), I don't think it's worth it.


In reply to [OT] Re^2: Populating an array via a DBI call - simplified by erix
in thread Populating an array via a DBI call - simplified by edimusrex

Title:
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, details, 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, summary, 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.