Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: swapping PIPE for comma in CSV file

by LighthouseJ (Sexton)
on Jun 27, 2007 at 14:24 UTC ( [id://623632]=note: print w/replies, xml ) Need Help??


in reply to swapping PIPE for comma in CSV file

I posted the solution above with only using perlfunc. I just registered this login today.

I found yet another solution, which is radically different from anything else I've seen.

I got to thinking about my other comment correcting someone else that we should be concerned less with the commas and more with the quotes because they provide a more concrete "rule" for delimiting the items. I was writing an array definition for another file and noticed the definition was identical to the provided data, so I wrote a program which simply evals the data into an array, then prints it out in the right format. I'm sure somebody can write something to clean up the output and make it more elegant but the eval does a bang-up job of reading the data properly.

#!/usr/bin/perl -w use strict; { while (<DATA>) { my @i = (); eval "\@i = ($_);"; print "\"$i[0]\"|\"$i[1]\"|\"$i[2]\"|\"$i[3]\"|$i[4]|$i[5]|\"$i[6] +\"|\"$i[7]\"\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",""
Hopefully this is useful to somebody.

"The three principal virtues of a programmer are Laziness, Impatience, and Hubris. See the Camel Book for why." -- `man perl`

Replies are listed 'Best First'.
Re^2: swapping PIPE for comma in CSV file
by Anonymous Monk on Jun 27, 2007 at 22:05 UTC
    oooo, oooo...

    perl -wlpe "s/(\042[^\042]*?\042)/'$1'/g; $_ = join '|', eval qq/($_)/" NSRLFile.csv > NSRLfile.psv
    see previous post for definitions of NSRLFile.* files.
    \042 is a " char.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2025-03-25 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (67 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.