CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
READ CSV and change delimiter

 



takahirata
New User

Nov 22, 2014, 7:16 AM

Post #1 of 2 (2529 views)
READ CSV and change delimiter Can't Post

HI,

I am new to PERL

I have a CSV file with below

line1A,"line1B,line1B",line1C
line2A,"line2B
line2B",line2C
line3A,line3B,line3C

I will like to convert this CSV file to

line1A;line1B,line1B;line1C
line2A;line2B~line2B;line2C
line3A;line3B;line3C

Need to change the delimiter "," to ";"
If cell is wrapped with " then we want to retain comma
If cell is wrapped with " and has multiple lines, convert to
a single line, and insert ~ as a line indicator

Can you tell me how we can accomplish this in PERL?


(This post was edited by takahirata on Nov 22, 2014, 7:17 AM)


FishMonger
Veteran / Moderator

Nov 22, 2014, 7:29 AM

Post #2 of 2 (2527 views)
Re: [takahirata] READ CSV and change delimiter [In reply to] Can't Post

Use the Text::CSV_XS module to parse the file and output the updated version.
http://search.cpan.org/~hmbrand/Text-CSV_XS-1.12/CSV_XS.pm

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives