in reply to swapping PIPE for comma in CSV file

Don't reinvent the wheel, use Text::CSV_XS:

#!/usr/bin/perl use warnings; use strict; use Text::CSV_XS; my $csv = Text::CSV_XS->new(); while (<DATA>) { my $line = $csv->parse($_); print join("|",$csv->fields)."\n"; } __DATA__ "00000142988AFA836117B1B572FAE4713F200567","9B3702B0E788C6D62996392FE3 +C9786A","05E566DF","J0180794.JPG",32768,3290,"WIN","" "000005EE5E3F6961B78CE4549270DE5D05CBC0CB","8D025B6AE1994A40FCBB5AEC2E +F273F9","5E8D7D42","WabIab, and more.bor",4760,4616,"WIN","" "0000085FC602CD8AD4793A874A47D286DACB0F6A","8BA8BC04896C421A704282E9B8 +7B5520","8D89A85D","fpSDt,Finder,Link.gif",1161,2988,"Solaris","" "00000FF9D0ED9A6B53BC6A9364C07074DE1565F3","A5D49D6DA9D78FD1E7C32D58BC +7A46FB","2D729A1E","cmnres,pdb.dll",76800,1550,"WIN",""

OTOH, why do this at all? Commas within quotation marks are common enough in CSV files and (as you've found out) are easy enough to handle.


All dogma is stupid.

Replies are listed 'Best First'.
Re^2: swapping PIPE for comma in CSV file
by dwhite20899 (Friar) on Jun 26, 2007 at 15:36 UTC
    Nice. I'll have to dig into CSV_XS.

    Yeah, I can handle it as is, but I'm getting asked to convert it for others who can't. It's due to a legacy spec that wasn't the greatest, but whatcha gonna do? (I got them to change the spec to put the three static width columns first, and paid for that with a lot of blood - not gonna ask for more)