Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: csv to xml

by Not_a_Number (Prior)
on Aug 06, 2016 at 10:28 UTC ( [id://1169250]=note: print w/replies, xml ) Need Help??


in reply to Re: csv to xml
in thread csv to xml

my @values = split ',',$data;

Unfortunately, this breaks if one of the 'values' itself contains a comma. And commas are not uncommon in company names.

Use eg Text::CSV.

Replies are listed 'Best First'.
Re^3: csv to xml
by Laurent_R (Canon) on Aug 06, 2016 at 12:49 UTC
    But Text::CSV will not help very much with the type of data shown in the original post, will it?

    AFAIK, it will also break on an additional comma unless there is some additional information, such as quotes, to help identify that the additional comma is not a field separator.

      Yes.

      If the CSV is well-formed, internal commas will be escaped in some way, eg:

      Ed Smith, "Smith, Brown & Jones", sbj@example.com, "999,999,999"

      Of course, if it isn't well-formed, I agree that Text::CSV will not help any more than a hand-rolled CSV parsing kludge...

        I'd say at this point, we just don't have enough info about the actual data and where it comes from. I am working with one CSV file now and I had a choice of the separator character and chose the pipe, "|", instead of comma ",". We've got a case here where the example data probably doesn't come close enough to the "real thing". The original code didn't come close to working either. If this is a "real" CSV, then Text_CSV will help.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-25 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found