Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

DBD::CSV and Macperl

by sz (Friar)
on Sep 01, 2000 at 05:40 UTC ( #30670=perlquestion: print w/replies, xml ) Need Help??
sz has asked for the wisdom of the Perl Monks concerning the following question:

Is there a macperl monk in the monastery?

I've installed DBI and DBI::CSV on my mac to do some quick and dirty processing of files delimited with bars (i.e. "|"). Below is the test code, adapted from the docs, that is giving me trouble. The problem is that it returns only the first row of the productDB test file (containing the table fields) rather than the whole table. Can anyone spot the problem? Having searched through the macperl mailing list archives I found only one unanswered posting with the same problem.

#!perl -w use DBI; use strict; my $dbh = DBI->connect("DBI:CSV:csv_sep_char=|:f_dir=Hard Disk:develop +ment") or die "Cannot connect: " . $DBI::errstr; $dbh->{'RaiseError'} = 1; $dbh->{'csv_tables'}->{'productDB'} = { 'file' => 'productDB', 'col_names'=>["product_id","product","price","name","image_url +","description","options"], }; my $sth = $dbh->prepare("SELECT * FROM productDB"); $sth->execute() or die "Cannot execute: " . $sth->errstr(); my @row; while (@row = $sth->fetchrow_array) { print ("Row: @row\n");} $sth->finish(); $dbh->disconnect;



Replies are listed 'Best First'.
RE: DBD::CSV and Macperl
by mattr (Curate) on Sep 01, 2000 at 06:53 UTC
    Hello, I believe the default is CRLF, so for Mac you may need this line: $dbh->{'csv_eol'} = "\015"; # lines end with ctrl-m Some other notes.. Vertical tabs, binary/two-byte code, and Excel may also mess up your data. I rebuilt SQL-HTML to use the DBD::CSV SQL wrapper for a couple projects of mine, and had to deal with unsupported functions, so careful of other SQL commands you might take for granted like list tables. Also you might also include "use Text::CSV_XS" (changing the default field separator to the pipe symbol) for direct manipulation routines but I found the quote methods to be spooky especially with Japanese data. Always safer to roll your own. Hope this helps, Matt Rosin

      Sorry about the lack of html formatting. Wanted to mention I might have found a bug in timing of writes to the disk, as I had trouble selecting all records to find the highest record number when automatically generating a new record number. This was solved by using a separate text file to store the highest record number.


Re: DBD::CSV and Macperl
by sz (Friar) on Sep 01, 2000 at 19:45 UTC
    Hi Matt,

    The funny thing is that when productDB is saved with mac eof characters and I use $dbh->{'csv_eol'} = "\015", I get an "function not supported" error from I've also tried it as dbh->{'csv_eol'} = \r

    The code only runs without error when the file has unix eol characters.

    I reviewed the text file and there were no problem characters. I'm at a loss as to why the code stops at the first line.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://30670]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2017-05-30 09:52 GMT
Find Nodes?
    Voting Booth?