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


In reply to A problem with Text::CSV by lihao

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.