UPDATE: It turns out that it was a problem with printing to STDERR in my version of Apache2. Now that I have upgraded Apache2 to the latest Debian packages, the problem is gone. Thanks all for your help.
I'm having trouble with Text::CSV_XS. I'm using it most simply, and I don't understand why things are failing. I am not getting any error messages, the script (which is a CGI-script) just hangs indefinitely, until the web server ultimately times out. I have narrowed the problem down to the following (simplified) function.
Please notice the comments EXAMPLE LINE 1 and EXAMPLE LINE 2. If I comment either one (or both) of those out, everything works fine. If I leave them both as they are now, uncommented, the script hangs and I never get an error message in my error logs. I don't understand what's causing this or how to fix it.
$fh is a filehandle created by CGI.pm and retrieved using
my $fh = $cgi->upload('product_list');
sub validate_data {
my ($self, $fh) = @_;
my $csv = new Text::CSV_XS({sep_char => "\t"});
my $headings = <$fh>; # Pull the column names off the top
$csv->parse($headings) or return;
my @headings = $csv->fields();
print STDERR Dumper(\@headings); # EXAMPLE LINE 1
while(my $line = <$fh>) {
if($csv->parse($line)) {
my %hash;
my @fields = $csv->fields();
print STDERR Dumper(\@fields); # EXAMPLE LINE 2
}
}
return 1;
}
I am using:
- perl v5.8.4 built for i386-linux-thread-multi
- I used CPAN to get the latest CSV_XS but I don't know how to tell what version it is.
- validate_data() is a sub inside a CGI::Application sub class called BulkUploadApp.pm.
- use Data::Dumper; is at the top of the module, right below use strict; and use warnings;
I forgot to mention: Dumping this data isn't really the important part. I'm using it to build a data structure, but any time I try to access data in the data structure, the script hangs!
Edit: I have switched to Text::Delimited and when using Dumper to see those results I get errors again. I can access all the values fine, I just can't view them with Dumper. It always hangs and the program won't exit. I have a bad feeling about this.