Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: parsing csv with Text::ParseWords

by Bloodnok (Vicar)
on Oct 09, 2009 at 01:05 UTC ( #800134=note: print w/replies, xml ) Need Help??


in reply to parsing csv with Text::ParseWords

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.

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: parsing csv with Text::ParseWords
by GertMT (Hermit) on Oct 09, 2009 at 11:34 UTC
    The CSV parsers gave a EOL problem. Thanks, I'll try and see if Text::xSV can help me.
      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.

        thanks for the information. I've had serious problems parsing a csv-file produced by a Filemaker database on a Mac. I'll have the export script from Filemaker changed (Filemaker has various options and we maybe took the wrong option). I've almost tried everything, \l, \r, \012, \015, \rn (maybe this one not but I've made note if it now).

        Hopefully with the new export format no trouble anymore.

        thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-12-07 02:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (33 votes). Check out past polls.

    Notices?