Arguably, this is a fairly easy question for someone with more Perl experience than I have.
Issue:
I have a quoted CSV file (created using MS Excel) that has data similar to the following:
"John Smith","41160","California","3/31/2010"
"John Adams","41166","Massachusetts","3/31/2010"
"Samuel Adams","41170","Maine","3/31/2010"
I'm using very simple Perl to load the data into an array and print out the fields (to ensure that the data was read correctly);
#!/usr/bin/perl
# open file
open(FILE1,"data.txt")or die ("Unable to open the file.");
# read file into an array and close
my @data = <FILE1>;
close (FILE1);
# Use a FOREACH loop to read through the data in the array
foreach $caseMetrics (@data)
{
($caseOwner,$caseNumber,$caseState,$openedDate, )=split(',',
+$caseMetrics);
print "$caseOwner\n";
print "$caseNumber\n";
print "$caseState\n";
print "$openDate\n";
}
What I find is that the array contains the all of the data EXCEPT the $openDate data. If I create a text file with the identical data the array does contain the $openDate data. NOTE: I am assuming that the data is not in the array because print "$openDate\n" doesn't return any data.
So, my question is, do I have to do something special work with a CSV file? It seems odd that all of the fields are good with the exception of $openDate so, I am assuming that I am overlooking something fairly simple here.
Thanks!