dukea2006 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Split ignores certain data in a Quoted CSV file.
by roboticus (Chancellor) on Apr 06, 2010 at 18:14 UTC | |
by dukea2006 (Novice) on Apr 06, 2010 at 18:18 UTC | |
|
Re: Split ignores certain data in a Quoted CSV file.
by toolic (Bishop) on Apr 06, 2010 at 18:21 UTC | |
by ikegami (Patriarch) on Apr 06, 2010 at 19:09 UTC | |
by snopal (Pilgrim) on Apr 07, 2010 at 15:23 UTC | |
|
Re: Split ignores certain data in a Quoted CSV file.
by roboticus (Chancellor) on Apr 06, 2010 at 18:19 UTC | |
|
Re: Split ignores certain data in a Quoted CSV file.
by AR (Friar) on Apr 06, 2010 at 18:20 UTC |