Try this ;
#!perl use 5.12.0; use warnings; use strict; use File::Basename; use Text::CSV_XS; use Benchmark; my $start = time; my $t0 = new Benchmark; print "\n Current Date and Time -> " . localtime() . "\n"; my $Base = 'c:/temp'; my $s_DIR=$Base.''; my $p_DIR=$Base.''; my $f_DIR=$Base.''; my @xFile = grep {-f $_} glob( "$s_DIR/x*.csv"); for my $csvfile (@xFile){ # input my ($name,$dir,$ext) = fileparse($csvfile, qr/\.[^.]*/ ); print "processing $name \n"; open my $IN,'<',$csvfile or die "Could not open $csvfile : $!"; # outputs my $f_Pass = $p_DIR."/pass_table_".$name.'.txt'; my $f_Fail = $f_DIR."/fail_table_".$name.'.txt'; open my $PASS,'>',$f_Pass or die "Can't open output file $f_Pass : $!"; open my $FAIL,'>',$f_Fail or die "Can't open output file $f_Fail : $!"; # process my $indexF = 0; my $indexP = 0; my $csv = Text::CSV_XS->new({ auto_diag => 1, binary => 1, callbacks => { after_parse => sub { $_ ||= 0 for @{$_[1] } }, } }); my $header = $csv->getline($IN); while ( my $colref = $csv->getline($IN) ){ my $col0 = shift @$colref; my $col1 = shift @$colref; if( $col1 == 1 ){ print $PASS join " ",@$colref,"\n"; $indexP = $indexP + 1; } else { print $FAIL join " ",@$colref,"\n"; $indexF = $indexF + 1; }; }; # report print " totalP $indexP totalF ".($indexF-0)." total ".($indexP+$inde +xF)." \n"; printf "%% totalP/(totalF+totalP) = %.2f %% \n",($indexP/($indexP+$i +ndexF)*100); close $PASS or die "Couldn't close output file $f_Pass : $!"; close $FAIL or die "Couldn't close output file $f_Fail : $!"; }; my $t1 = new Benchmark; my $td = timediff($t1, $t0); printf "\nCode took: %s\n",timestr($td); printf "++Finished program in -> %5.2f seconds\n\n",time-$start;
poj

In reply to Re^3: csv parsing with multiple missing values/multiple commas by poj
in thread csv parsing with multiple missing values/multiple commas by f77coder

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.