MrCromeDome has asked for the wisdom of the Perl Monks concerning the following question:

Still working on publishing my league's hockey stats to the web. Thought things were going well until DBD::CSV started giving me some problems.

I've been developing the site on my Win2k machine, with Apache 1.3.20 and ActiveState Perl 5.6.1.628. I had some of the stats pages done. . . they looked really good and worked well, so I thought I'd move them to my web server (Slackware 8.0, Apache 1.3.23, Perl 5.6.1) for people to admire. The scripts run fine there, but I have no data displayed. The graphics and tables generated come out exactly as intended, but no data is displayed from my CSV files. Even more strange, I'm not getting any errors generated. I've included some code below to give a feel for what I'm doing:

$sql = $filehandle->prepare($script) || die "Couldn't prepare SQL: " . $filehandle->errstr; $sql->execute() || die "Couldn't prepare SQL: " . $filehandle->errstr; while (my $row = $sql->fetchrow_hashref) { my %row_data; $row_data{TEAM} = $row->{'Team'}; push(@table, \%row_data); } $sql->finish();
My connect() call doesn't error out, and I've displayed messages on the web page to show what directory the script was pulling files from to verify they were coming from the right spot (they were). I've even wrote a little script to get the list of tables being used, and all of my CSV files were listed. As a final effort, I made sure that all my unix file permissions were set properly, and again, they were.

What gives? Any clue as to what I'm doing wrong? Any insight is certainly appreciated.

Thanks,
MrCromeDome

Replies are listed 'Best First'.
Re: Problems using DBD::CSV
by lachoy (Parson) on Feb 14, 2002 at 16:45 UTC

    You might also see if the line endings are what DBD::CSV thinks they should be. Win32 programs have a tendency to stick a carriage-return at the end of every line, which might screw up DBD::CSV from reading the file properly unless you tell it so using the csv_eol setting in the connect() call.

    Chris
    M-x auto-bs-mode

      That seemed to do the trick! Changed my connect line to this:
      my $filehandle = DBI->connect("DBI:CSV:f_dir=$files;csv_eol=\n");
      and things worked like a charm :)

      Thanks for all the help,
      MrCromeDome

(jeffa) Re: Problems using DBD::CSV
by jeffa (Bishop) on Feb 14, 2002 at 16:27 UTC
    I wish you had included the code that opens and reads the CSV files. Are the CSV files empty?

    After the execute() call, try adding this:

    use Data::Dumper; print STDERR Dumper $sql->selectall_arrayref();
    watch your error log and see if you are even pulling data out.

    Hope this helps ...

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      The CSV files all have data. . . same files that display ok on my Win2k machine.

      Some more code for your viewing (dis)pleasure:

      my $files = $info{PATH_BASE} . $info{PATH_DATA}; my $filehandle = DBI->connect("DBI:CSV:f_dir=$files"); or die "Could not connect to database: " . DBI->errstr; $script = "SELECT Drafted, " . " Team, " . " Owner, " . " Location, " . " Age " . " FROM owners " . " ORDER BY Drafted ASC " ; $sql = $filehandle->prepare($script) || die "Couldn't prepare SQL: " . $filehandle->errstr; $sql->execute() || die "Couldn't prepare SQL: " . $filehandle->errstr; while (my $row = $sql->fetchrow_hashref) { my %row_data; $row_data{TEAM} = $row->{'Team'}; push(@table, \%row_data); } $sql->finish(); $tmpl_owners->param( LEAGUENAME => $info{LEAGUENAME}, TEAMS => \@table ); return $tmpl_owners->output;
      $info{PATH_BASE} . $info{PATH_DATA} turn out to be /www/cromedome.net/data/, which is what they should have been. It seems I never make it into while loop - I don't think that I'm pulling any data whatsoever. Should I execute that after the execute() and before the while()?

      MrCromeDome

Re: Problems using DBD::CSV
by rdfield (Priest) on Feb 14, 2002 at 16:35 UTC
    I've often had problems moving from Win32 platforms to *NIX, all because of case sensitivity. Make sure your filenames have the same casing as your program expects.

    rdfield