http://www.perlmonks.org?node_id=1026881


in reply to Regex Split and Formatting

*Update* : Oh yes .. I forgot to mention.. i'm not allowed to use any modules..

Parsing CSV isn't your real problem; this is your real problem.

CSV is one of those things that seems simple and easy to handle at first glance. But, once you start digging in and coming across corner-cases, you realized it can be very tricky to get right. You mention the embedded newlines, but what about embedded commas (commas inside quoted fields)? Are all fields quoted? Can you guarantee that? What about escaped quotes inside of quoted fields?

Unless this is a homework assignment, or you have strange desire to reinvent the wheel (in which case you should be reviewing the code in existing CSV modules), you would be better off copying and pasting Text::CSV into your program than you would be in trying to recreate it.

Christopher Cashell