Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Converting File Delimiters

by aaron_baugher (Deacon)
on Aug 13, 2012 at 21:52 UTC ( #987222=note: print w/ replies, xml ) Need Help??


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

What does "dies on the first row" mean? Does it give you an error message? Can you show the input line that it dies on, perhaps with a couple lines before and after it for context? Also, check the documentation for Text::CSV for info on using binary or different encodings, in case your input has any characters that are not simple ASCII text.

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


Comment on Re^3: Converting File Delimiters
Re^4: Converting File Delimiters
by mmueller44 (Novice) on Aug 16, 2012 at 16:40 UTC

    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

      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.

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987222]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-08-01 04:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls