Advice on handling malformed CSV with FasterCSV

Discussion in 'Ruby' started by Wes Gamble, Dec 18, 2006.

  1. Wes Gamble

    Wes Gamble Guest

    All,

    FasterCSV 1.0.0
    Ruby 1.8.4

    I am writing functionality to replace an an older system. Part of this
    system accepts uploaded CSV files, parses, and displays their contents.
    When confronted with a file including one line that looks like this:

    "data",'otherdata"

    the legacy app. happily parses this into two fields with values data and
    otherdata.

    However, FasterCSV fails because of the quote mismatch on the 2nd field
    and throws a MalformedCSVError when you attempt to manipulate the object
    returned from FasterCSV.open().

    I've taken a look at the code and I can see where the quote matching is
    enforced and so I have a pretty good idea of how to "fix" this (which I
    am only even considering because I'm trying to match the legacy
    functionality).

    I need some advice. My questions are:

    1) Is there a way to get FasterCSV to accept input like the above? How
    can I set up a custom parsing scheme?
    2) Should I modify the FasterCSV parser directly to accept this sort of
    input?
    3) Should I pre-process the file to eliminate/modify these sorts of
    cases to improve the likelihood of a successful FasterCSV parse?

    Thanks,
    Wes

    --
    Posted via http://www.ruby-forum.com/.
     
    Wes Gamble, Dec 18, 2006
    #1
    1. Advertisements

  2. Wes Gamble

    Wes Gamble Guest

    Paul Lutus wrote:
    > I strongly recommend that you normalize the database to conform to CSV
    > conventions, before performing any processing. This is much to be
    > preferred
    > to rewriting a standard library in such a way that it accepts the
    > malformed
    > data.


    I agree.

    Thanks, Paul.

    Wes

    --
    Posted via http://www.ruby-forum.com/.
     
    Wes Gamble, Dec 18, 2006
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michal Mikolajczyk
    Replies:
    0
    Views:
    908
    Michal Mikolajczyk
    Feb 13, 2004
  2. Tintin92
    Replies:
    1
    Views:
    2,121
    Andrew Thompson
    Feb 14, 2007
  3. James Edward Gray II
    Replies:
    0
    Views:
    167
    James Edward Gray II
    Nov 16, 2005
  4. Mark Stroeve
    Replies:
    2
    Views:
    396
    Brian Candler
    May 18, 2007
  5. Li Chen
    Replies:
    10
    Views:
    299
    Rob Biedenharn
    Sep 24, 2008
  6. John Mcleod
    Replies:
    1
    Views:
    229
    John Mcleod
    Jul 16, 2009
  7. John Mcleod
    Replies:
    16
    Views:
    382
    John Mcleod
    Nov 17, 2009
  8. John Mcleod

    using FasterCSV to clean CSV file

    John Mcleod, Nov 17, 2009, in forum: Ruby
    Replies:
    7
    Views:
    345
    James Edward Gray II
    Nov 18, 2009
Loading...