GertMT has asked for the
wisdom of the Perl Monks concerning the following question:

dear Monks,

While reading a csv-file I've had some trouble using Text::CSV_XS for a reason that might have to do with eol (re. my post from y'day where Tux and ELISHEVA give me valuable info). That's why I'm trying to use Text::ParseWords but I just can't get to the final stage and was wondering if someone could help me.

I know that there's a lot of 'fields' as I counted them. While trying to print them in an orderly way I get all of them (not orderly and commented out) or just the value of the elements from the first line.

The last line of code obviously doesn't make sense. The fields should be coming from 'every single line', (@lines? and not @fields?)

Needless to say I'm not able to use the defined variables.What am I doing wrong?

I did check some docs on refences and so but all is a bit confusing now.

As I didn't partake of the original discussion to which you allude, the question that immediately raises its head for me is: Why not use one of the CSV parsers, in particular (and the regulars can guess what's coming now:-), Text::xSV.

The EOL in Perl source is just "\n". On Unix that literally is all that there is. On Windows, there is a \r\n sequence. I would assume that you don't need to specify EOL for your CSV module, just let Perl do its default thing, eg leave EOL => 'x' off! And let default do its work.

I have moved files between Unix and Windows and Perl can read files created in either place. When I save a file under Unix, EOL is just \n. When saved under Windows it is \r\n. The Windows Perl can read the Unix Perl's file and vice-versa. My normal text editor, TextPad can do the same thing.

If you process a Windows file that came from a Unix system, when Perl writes it, it will put in the \r\n sequence for Perl "\n". When the Unix Perl writes a file that came from Windows, it just puts in \n instead of \r\n.

So in Perl: print "qwerty\n"; the \n may be 2 characters depending upon which OS you are running Perl under.

If you could explain this problem more with an example, that would be helpful. This is a well-known common problem.

I don't know the full history of why Windows did it this way. But in ancient mechanical paper tape days, each line ended with "carriage return(\r), line feed(\n), rubout(del). The teletype machine was dumb and need the \r to return print head to the next line and \n to advance the paper. The rubout (all 8 positions punched) was to keep mechanical fingers lubricated via the oil on the tape. The ASR 33 teletype was a "dodo bird" by even the time of DOS.
Anyway this EOL problem is well known and there are solutions.

Here is a sample script you may possibly find useful for parsing csv files - http://www.biterscripting.com/SS_CSV.html.
The scripting language is NOT perl - I am posting it since some users may find it simpler for parsing CSV files.