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!


In reply to Split ignores certain data in a Quoted CSV file. by dukea2006

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.