Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Output results from a DBI select query in one line

by mjg (Beadle)
on Apr 11, 2006 at 15:47 UTC ( #542573=snippet: print w/replies, xml ) Need Help??
Description: I'm finding myself using this idiom a lot for a current project. Adjust to taste for your own applications.
# given a DBI handle $dbh, a database table "foo" with a column "bar"

print join "\n", map join("\t", @$_), @{$dbh->selectall_arrayref( q{
   select bar from foo
} )};
Replies are listed 'Best First'.
Re: Output results from a DBI select query in one line
by merlyn (Sage) on Apr 11, 2006 at 16:12 UTC
      Or, a couple of characters shorter than that (if we don't count loading Dumper):
      print Dumper $dbh->selectall_arrayref("SELECT one, two FROM three WHER +E four=? AND five=?",{},4,5);
        Either merlyn's or jZed's examples are fine for diagnostics. The original, however:
        • won't truncate values as dump_results does
        • provides more human-readable output than Data::Dumper's structures
        But feel free to use whatever works for you. Mine was just more appropriate for my project.
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: snippet [id://542573]
help
Chatterbox?
[Corion]: Heh - I just realized, $work management just declared "no raises for anybody this year", and I'm not even angry about that. Even though that implicitly means "raises for the people with an automatic 5% raise in their contract", which the newly-merged ...
[Corion]: ... coworkers have. But I guess I've gone more mellow since I get to relax more, and such stuff doesn't make me as angry as it used to.
[Corion]: $boss will still get to listen to my interpretation :-D
[Eily]: hey, I'm just behind Larry in SioB \o/
[Corion]: Eily: Wheee ;)
[Eily]: I'll add that to my résumé

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2018-01-22 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How did you see in the new year?










    Results (233 votes). Check out past polls.

    Notices?