Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Mapping to an associative hash

by IOrdy (Friar)
on Sep 17, 2003 at 01:56 UTC ( #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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-02-05 14:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?