Tuesday, July 8, 2008

Read data from a csv file using perl (when the column count is known)

I need to read a csv file, and process each and every column data (i know the column count before processing the file)


#!/usr/local/bin/perl

open FILE, "< test.csv" or die "Can't open test.csv : $!";
while(
){
chomp;
($col1,$col2,$col3,$col4) = split ("\t");
print "$col1 \t";
print "$col2 \t";
print "$col3 \t";
print "$col4 \t";
print "\n";
}
close FILE;

No comments: