#!/usr/bin/perl
use strict;
use Text::CSV;
####
my $input="input.csv";
my $output="output.txt";
my $trash="trashfile";
my $csv=Text::CSV->new(); #Creates a new Text::CSV object
open(INFILE,$input) || die "Can't open file $input";
open(OUTFILE,">$output") || die "Can't open file $output";
open(TRASH,">$trash") || die "Can't open file $trash";
##
##
while () {
if (/"X"/) { #The trash data has these 3 characters in it
print TRASH "$_\n";
}
else { #Now to deal with the data I want to keep
if($csv->parse($_)) { #checks to see if data exists in $_ and parses it if it does
my @fields=$csv->fields; # puts the values from each field in an array
my $elements=@fields; #gets the number of elements in the array
for ($x=0;$x<$elements;$x++) {
print OUTFILE "$fields[$x]\t";
}
}
}
}
##
##
close INFILE;
close OUTFILE;
close TRASH;
unlink $trash;