Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

thezip's scratchpad

by thezip (Vicar)
on Feb 15, 2007 at 16:36 UTC ( #600240=scratchpad: print w/replies, xml ) Need Help??

DBD::CSV issue

CSV datafile excerpt

mcc,source,alias 450215,4100,0006 450207,4100,0011
#!/perl/bin/perl use strict; use warnings; use autodie; use JAD::Common::Log; use JAD::Common::Database::CSV; use JAD::Config; use JSON; my $cfg = JAD::Config->new(); my $log = JAD::Common::Log->new('csv_log.txt'); my $csv_db = JAD::Common::Database::CSV->new(); my $json = JSON->new()->canonical()->pretty(); my $db_file = sprintf('%s/CSV_db/%s', $cfg->param('billing', 'accounting'), 'ct_pd_printer_alias.csv' ); my $SQL = qq( SELECT mcc, source, alias FROM $db_file ); my $data = $csv_db->select($SQL); $log->logit($json->encode($data), {'ECHO' => 1} );

The select method:

#--------------------------------------------------------------------- +---- sub select { #--------------------------------------------------------------------- +---- my($self, $SQL) = @_; # Connect to the CSV database my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { 'f_ext' => ".csv", 'f_encoding' => "utf-8", 'RaiseError' => 1, 'schema' => undef, }) or die $DBI::errstr; my $sth = $dbh->prepare($SQL); $sth->execute(); while (my $row = $sth->fetchrow_hashref) { print $json->encode($row); next; } exit(0); my $resultset = []; while (my @row = $sth->fetchrow_array) { push(@$resultset, \@row); } return $resultset; }
Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2017-02-19 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (292 votes). Check out past polls.