in reply to Re^3: Converting File Delimiters
in thread Converting File Delimiters

By die, I mean the script just stops with no error messages.

It creates the first 67 rows until row 68 which is the first row with double quotes around the field with the comma imbedded within the quotes. See row 3 and 4 of data below

988A5370, 98_1V_HB, ADVANCED ROTORCRAFT SYSTEMS, false, store, false, +, , , , unspecified, USD, false, +, true, +, false, +, false, +, fals +e, + 988A5521, 98_1V_HB, Hel Product Pool (Pds Dd), false, store, false, , +, , , unspecified, USD, false, +, true, +, false, +, false, +, false, + + 988A5707, 98_1V_HB, "Chinook, IPT ME Support", false, store, false, , +, , , unspecified, USD, false, +, true, +, false, +, false, +, false, + + 988A5708, 98_1V_HB, "Chinook, ME Factory Supt", false, store, false, , + , , , unspecified, USD, false, +, true, +, false, +, false, +, false +, + 988A5761, 98_1V_HB, Tandem Rotor Configuration Mgt, false, store, fals +e, , , , , unspecified, USD, false, +, true, +, false, +, false, +, f +alse, + 988A5762, 98_1V_HB, RECAP-Product Data Management, false, store, false +, , , , , unspecified, USD, false, +, true, +, false, +, false, +, fa +lse, +

Any suggestions would be great. Thanks, Mike

Replies are listed 'Best First'.
Re^5: Converting File Delimiters
by Tux (Canon) on May 22, 2013 at 06:42 UTC
    my $ic = Text::CSV->new ({ binary => 1, allow_whitespace => 1, auto_di +ag => 1 });
    allow_whitespace When this option is set to true, whitespace (TAB's and SPACE's) surrounding the separation character is removed when parsing. If either TAB or SPACE is one of the three major characters "sep_char", "quote_char", or "escape_char" it will not be considered whitespace. Now lines like: 1 , "foo" , bar , 3 , zapp are correctly parsed, even though it violates the CSV specs. Note that all whitespace is stripped from start and end of each field. That would make it more a feature than a way to enable parsing bad CSV lines, as 1, 2.0, 3, ape , monkey will now be parsed as ("1", "2.0", "3", "ape", "monkey") even if the original line was perfectly sane CSV.

    Enjoy, Have FUN! H.Merijn
    2.0
Re^5: Converting File Delimiters
by aaron_baugher (Curate) on Aug 20, 2012 at 17:29 UTC

    I think this may be because your delimiter is actually comma-space, rather than just a comma as I was assuming, and which is the default of Text::CSV. So it sees those fields as beginning with a space and including a double quote, rather than quoted by a pair of double quotes between two commas. I tried changing the delimiter for the input file to comma -space, and it worked much better:

    my $ic = Text::CSV->new({sep_char => ', '}) + or die Text::CSV->error_diag();

    Aaron B.
    Available for small or large Perl jobs; see my home node.