Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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
[marto]: Corion you under estimate how lazy these admins are :P
[Discipulus]: we too; using opsview alarms
[marto]: the key word: outsourcing ;)
[Corion]: marto: Yeah, feels like that ;) You could set up the cronjob that auto-creates tickets :-))
[marto]: the ticketing system does not accept calls via email, nor has it a working API. It's tied into Active Directory for authentication and the Solaris boxes aren't on that domain
[Corion]: The one thing I haven't figured out a solution to is how to get an edge-trigger instead of sending an email every 5 minutes if the usage is above 90%. I want one mail when it goes over 90% but no more emails as long as it stays between 90% and 95%.
[Corion]: marto: Clever! ;)
[Corion]: You can only reach me by pager
[Corion]: Maybe the solution would be to launch a cron job every minute that takes two measurements a minute apart and sends a mail if the usage is below on the first and above threshold on the last measurement
[marto]: that's essentially it :)

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (9)
As of 2017-01-24 10:10 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (203 votes). Check out past polls.