CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
DBD::CSV Bad File number at line 210

 



zatlas1
User

Oct 8, 2015, 6:16 AM

Post #1 of 9 (2517 views)
DBD::CSV Bad File number at line 210 Can't Post

Hi all

I work on Solaris (8, I think) with Perl 5.10.0

I do this simple code (it went through many iterations to try to resolve:)


Code
 
my $indir = "/home/myhome/";
my $infile = "ForMe_Info.csv";

my $dbh = DBI->connect("dbi:CSV:", undef, undef,{
f_dir => $indir,
RaiseError => 1,
'csv_quote_char' => "\'",
'csv_sep_char' => ",",
'eol' => "\n"
}) or die "Cannot connect: $DBI::errstr";

print "connected\n";
my $sth = $dbh->prepare ("select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv")
or die "Cannot prepare: $DBI::errstr";
$sth->execute or die "Cannot execute: $DBI::errstr";
print "Executed\n";




I get:

connected
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanInfo.pl line 29.
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanInfo.pl line 29.



I've done a lot of DBD::CSV on windows and Linux. Never had this problem. Could somebody please shed any light



Thanks

ZA


FishMonger
Veteran / Moderator

Oct 8, 2015, 6:32 AM

Post #2 of 9 (2515 views)
Re: [zatlas1] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

Please attach a sample (short) csv that demonstrates this issue so that I can run a couple tests to see if I can duplicate the issue and find the cause.


zatlas1
User

Oct 8, 2015, 6:50 AM

Post #3 of 9 (2511 views)
Re: [FishMonger] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

Sure thing

Here are the first 3 lines of the csv

Thank you
Attachments: ForMe_Info.csv (0.42 KB)


FishMonger
Veteran / Moderator

Oct 8, 2015, 7:19 AM

Post #4 of 9 (2503 views)
Re: [zatlas1] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

Have you verified that this sample csv file fails the same way as your full file?

So far, I've tested it on a Win7 system with perl v5.20.2 and was unable to reproduce the issue.

I'm now installing DBD::CSV on a CentOS system but it failed while installing the SQL::Statement prereq. I'll check one of the other Linux systems I have access to.


zatlas1
User

Oct 8, 2015, 7:45 AM

Post #5 of 9 (2498 views)
Re: [FishMonger] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

Yep, same results with the short file as well.



connected
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanAutosysInfo.pl line 29.
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanAutosysInfo.pl line 29.


ZA


FishMonger
Veteran / Moderator

Oct 8, 2015, 7:50 AM

Post #6 of 9 (2496 views)
Re: [zatlas1] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

Ok, I've tested it on CentOS with perl v5.10.1 and was unable to duplicated the issue you're seeing, however, I added additional code to dump the fetched data but it didn't fetch anything.


Code
#!/usr/bin/perl 

use warnings;
use strict;
use DBI;
use DBD::CSV;
use Data::Dumper;

my $indir = "/home/rkb/Downloads";
my $infile = "ForMe_Info.csv";

my $dbh = DBI->connect("dbi:CSV:", undef, undef,
{
f_dir => $indir,
RaiseError => 1,
'csv_quote_char' => "'",
'csv_sep_char' => ",",
'eol' => "\n"
}
) or die "Cannot connect: $DBI::errstr";
print "connected\n";

my $sth = $dbh->prepare ("select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from $infile")
or die "Cannot prepare: $DBI::errstr";

$sth->execute or die "Cannot execute: $DBI::errstr";
print "Executed\n";

print "Retrieving records\n";
while (my $record = $sth->fetchrow_hashref) {
print "record:" . Dumper $record;
}

print "Disconnecting\n";
$dbh->disconnect;



Quote
[root@isapps104 rkb]# ./zatlas1.pl
connected
Executed
Retrieving records
Disconnecting



zatlas1
User

Oct 8, 2015, 7:56 AM

Post #7 of 9 (2492 views)
Re: [FishMonger] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

I'll have to conclude that there is an issue with DBD::CSV in Perl 5.10.0 on Solaris 8 and I'll save the file as an Excel. Since I am struggling with that for a while, I know that accessing the file with

use Spreadsheet::ParseExcel;

would work.

Thank you

ZA


FishMonger
Veteran / Moderator

Oct 8, 2015, 8:04 AM

Post #8 of 9 (2490 views)
Re: [zatlas1] DBD::CSV Bad File number at line 210 [In reply to] Can't Post


In Reply To
Yep, same results with the short file as well.



connected
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanAutosysInfo.pl line 29.
DBD::CSV::st execute failed: Error while reading file /home/myhome/ForMe_Info.csv: Bad file number at /opt/perl.v5.10.0/lib/site_perl/5.10.0/DBD/CSV.pm line 210, <GEN0> chunk 1.
[for Statement "select JOBNAME, MACHINE, COMMAND, PROFILE, OWNER from ForMe_Info.csv"] at scanAutosysInfo.pl line 29.


ZA


"Bad file number at ..."

That's an odd error. I would have thought it would be "Bad file descriptor at".

My google searchs for "Bad file number at" have not been fruitful.


FishMonger
Veteran / Moderator

Oct 8, 2015, 8:07 AM

Post #9 of 9 (2489 views)
Re: [zatlas1] DBD::CSV Bad File number at line 210 [In reply to] Can't Post

perl v5.10.0 is known to be buggy. I would highly recommend upgrading it and the DBI/DBD modules.


Quote
I know that accessing the file with

use Spreadsheet::ParseExcel;


Since it's a csv file, why not use Text::CSV?
More specifically, Text::CSV_XS


(This post was edited by FishMonger on Oct 8, 2015, 8:08 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives