lihao has asked for the wisdom of the Perl Monks concerning the following question:
hello, monks
I got a weird problem when using Text::CSV to process a list of 119880 records/lines saved in in.csv, the code I am using is as follows:
#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $csv = Text::CSV->new({ binary => 1, allow_whitespace => 1, allow_loose_quotes => 1, }) or die Text::CSV->error_diag (); open my $csvfile, '<', 'in.csv' or die "cannot open in.csv for reading +: $!"; open my $fout, '>', 'out.txt' or die "cannot open out.txt for writting +: $!"; my $line_no = 0; while (my $record = $csv->getline($csvfile)) { $line_no++; my $value = "$record->[9], $record->[7], $record->[8] $record->[1 +0]"; printf {$fout} "[%06d] %s\n", $line_no, $value; } __END__
By running this code, I got only 119606 records in out.txt.. so how can I detect the 274 missing records. or are there any robust ways to grab records from a CSV file and process its fields within a while loop.
BTW. I used wc -l filename to count the number of lines contained in filename.
Thanks
lihao
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A problem with Text::CSV
by Tux (Canon) on Mar 26, 2008 at 20:23 UTC | |
by lihao (Monk) on Mar 26, 2008 at 20:49 UTC | |
by lihao (Monk) on Mar 26, 2008 at 20:40 UTC | |
by Tux (Canon) on Mar 27, 2008 at 07:36 UTC | |
|
Re: A problem with Text::CSV
by Narveson (Chaplain) on Mar 26, 2008 at 20:43 UTC | |
|
Re: A problem with Text::CSV
by apl (Monsignor) on Mar 26, 2008 at 20:26 UTC |