Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Search/Replace within fields of CSV

by CountZero (Bishop)
on May 08, 2015 at 18:41 UTC ( [id://1126141]=note: print w/replies, xml ) Need Help??


in reply to Search/Replace within fields of CSV

If you can edit the CSV file and add a first line with field names (I used "First,Second,Third,Fourth,Fifth,Sixth,Seventh,Eight"), then you can use DBI and SQL to do this job for you.
use Modern::Perl; use DBI; my $dbh = DBI->connect( "dbi:CSV:", undef, undef, { f_ext => '.csv', f_dir => 'D:/Perl/scripts', RaiseError => 1, } ) or die "Cannot connect: $DBI::errstr"; $dbh->do(q/UPDATE test SET First = 'CONDENSED' WHERE test.First = 'C'/ +); $dbh->do(q/UPDATE test SET First = 'FINAL' WHERE test.First = 'F'/); $dbh->do(q/UPDATE test SET Fifth = 'Ohio' WHERE test.Fifth = '0H'/); $dbh->do(q/UPDATE test SET Fifth = 'Oregon' WHERE test.Fifth = '0R'/);

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-24 22:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found