Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Textfile to csv with a small twist

by jZed (Prior)
on Aug 25, 2005 at 19:12 UTC ( [id://486694]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Textfile to csv with a small twist
in thread Textfile to csv with a small twist

Your code has this:
print $data{$columns[$c]}[$i]; print "," if $c < $#columns;
That attempts to construct a CSV record by merely putting commas between fields. If there is anything in the field (for example the newlines the OP requested), then you will not end up with a valid CSV file. Text::CSV_XS has the combine() method that will properly create records by not only inserting commas, but also, when called for quoting and escaping the field data. Other CSV modules like Text::xSV have similar methods to not only parse CSV correctly, but to produce it correctly.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2024-04-23 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found