Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: parsing CSV file with embedded commas (fortunately, fixed-width) - is unpack the solution?

by amelinda (Friar)
on Oct 31, 2001 at 22:44 UTC ( #122399=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-10-20 09:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?