Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Mapping to an associative hash

by IOrdy (Friar)
on Sep 17, 2003 at 01:56 UTC ( [id://292019]=note: print w/replies, xml ) Need Help??


in reply to Mapping to an associative hash

You could use DBD::CSV and supply the column names when you create the db handle. Then just $sth->fetchrow_hashref like you would any other sql query result.

update: added some code :)
my $dbh = DBI->connect(q{DBI:CSV:}); $dbh->{'csv_tables'}->{'mytable'} = { 'file' => 'mytable.csv', 'sep_char' => "\t" 'col_names' => ["col_a", "col_b", "col_c"] }; my $sth = $dbh->prepare("SELECT m.col_a, m.col_c FROM mytable m"); $sth->execute; my @rows; while (my $row = $sth->fetchrow_hashref) { push @rows, $row; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://292019]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found