C:\Documents and Settings\jnorton>ppm install Text::CSV
Downloading ActiveState Package Repository packlist...not modified
Downloading Text-CSV-1.13...done
Unpacking Text-CSV-1.13...done
Generating HTML for Text-CSV-1.13...done
Updating files in site area...done
4 files installed
####
$colref = $csv->getline ($io);
####
use strict;
use warnings;
my $out = "Rows_of_interest.txt";
open (OUT, "+>$out");
open my $fh, "<", "gridall.csv" or die "gridall.csv: $!\n";
my $all_lines;
my $matched_line_count;
#my $csv;
while (my $row = my $csv->getline($fh)) {
$all_lines++;
$row->[8] =~ m/^CE$/ or next;
print OUT $row;
$matched_line_count++;
}
$csv->eof or $csv->error_diag ();
print "\n\nNumber of lines detected:\t$all_lines\n\n";
print "\n\nNumber of matched lines detected:\t$matched_line_content\n\n";
####
C:\>test
Global symbol "$csv" requires explicit package name at C:\test.pl line 21.
Global symbol "$csv" requires explicit package name at C:\test.pl line 21.
Global symbol "$matched_line_content" requires explicit package name at C:\test.
pl line 24.
Execution of C:\test.pl aborted due to compilation errors.
####
$csv->eof or $csv->error_diag ();
####
aa,bb,cc,dd,ee,ff,gg,hh,CE,ii,jk,ll
####
use strict;
use warnings;
use Text::CSV;
my $out = "Rows_of_interest.txt";
open (OUT, "+>$out");
open my $fh, "<", "gridall.csv" or die "gridall.csv: $!\n";
my $all_lines = 0;
my $matched_line_count = 0;
my $csv = new Text::CSV();
while (my $row = $csv->getline($fh)) {
$all_lines++;
$row->[8] =~ m/^CE$/ or next;
print OUT $row;
$matched_line_count++;
}
$csv->eof or $csv->error_diag ();
print "\n\nNumber of lines detected:\t$all_lines\n\n";
print "\n\nNumber of matched lines detected:\t$matched_line_count\n\n";
__END__
Output is:
Number of lines detected: 1
Number of matched lines detected: 1
####
$row->[8] =~ m/^CE$/ or next;