in reply to Text::CSV_XS and "binary" mode

Did you also call binmode INFILE?

What exactly is in your record, and what do you expect to be there?

Replies are listed 'Best First'.
Re^2: Text::CSV_XS and "binary" mode
by bittis (Sexton) on Jan 26, 2009 at 08:38 UTC
    Hey there, i tried calling binmode INFILE but it seems to have made no difference. An example record is this (printed out nicely):
    LOGID: 123 LOGDATE: 04-Dec-2006 EMPID: 23 CATEGORY: Software SUBCAT: OS: DESCR: he needs russian fonts ACTION: installed cyrillic support needs additional fonts ASSIGNTO: 1 STATUS: C
      I see a number of problems in the posted code. But you are able to get some kind of printout until the end-of-line. I suspect a problem there. You should NOT use bin mode! This can be big trouble! A .CSV file is ASCII, not binary.

      I suspect that you have kind of inter-change problem between Windows and Unix. On Windows end-of-line is "\r\n", on Unix this is just "\n".

      Normally Perl will do "the right thing" for this translation, eg, it doesn't matter all all. Using Bin mode can defeat this "smarts". That is a different thing than how you move files between systems, but most of these things are pretty smart too and I use a number of them. For an ASCII file you shouldn't use bin mode for the transfer.

      post just a couple lines of your file it you can. It is hard for me to understand what you are trying to do from what I've seen so far.

      Edit: Looking more at the Text::CSV_XS module and it appears that I am wrong above. This module does have some trouble with \n. I have used this before but only in conjunction with DBI and SQL modules that evidently don't have this problem. Anyway post a couple lines of the CSV db (don't use "real" data that would cause problems), just an example.

        Hey there, the csv file was from an oracle db export of a specific table. The following are 2 lines
        456,05-Dec-2002,80,Software,print,,he can't print hes getting error ms +g: 'LPTTS FOR EC-2-1,paper jam,1,C 457,05-Dec-2002,22,Software,switchb.,,when internal call to ext 444 it + goes to switchboard2 - when internal call to 0 it goes to switchboar +d1 -- both should go to switchboard 1,call texchnitian - fixed ,35,C
        Using bin mode in CSV files was what i saw in the documentation for solving problems with commas inside fields with commas. Once a comma comes up in the field it all breaks. Is it easier to export a CSV file using a different separation character? Would this solve any carriage return problems? If so what character would you recommend using?
      That still doesn't tell me what you expected, what you get, and how these two differ. You might want to use Data::Dumper (set $Data::Dumper::Useqq = 1) to get an accurate description of your string.
        The line itself is returned correctly. The problem is that if for example the Action field contains a comma, then the what i get in the next field is the string after the comma and not the correct assign to ID, which is then place in the STATUS field instead, leaving me with an additional field in the end. Is this clearer? :/