in reply to parsing CSV file with embedded commas (fortunately, fixed-width) - is unpack the solution?

Bother. I should have mentioned an additional quirk.

One reason I went with split is for the following construction:
push (@items, [split(/,/, $line)]); where @items is a LoL.

If I have to go with unpack, how should I go about pushing them into @items?

Did I mention that this is not going to be on my server, so I can't rely on the presence of modules? :sigh:

Update: go go gadget unpack. It works now.

Thanks go especially to tye. I appreciate the other answers too (I'm definitely going to look into Text::ParseWords and Text::xSV for this in the future with cleaner data), but most of them had issues with either the the embedded comma or the embedded single quote.

As for those who berated me (again) for not wanting to use modules, I submit that I looked to unpack because a) it looked like the only solution that would cope with the embedded delineators issue and b) I didn't really understand how unpack works and I knew I needed to learn about it... especially if i am ever to grok obfuscated code. :)

Update 2: To clarify, these would be unescaped commas and quotemarks. Also, I didn't provide a line of data here that had an unescaped, embedded quotemark, but I do have some.

  • Comment on Re: parsing CSV file with embedded commas (fortunately, fixed-width) - is unpack the solution?
  • Select or Download Code