in reply to Re^4: Replace value in the text file
in thread Replace value in the text file
Here's a template for using Text::CSV that you can edit based on your needs (you should also install Text::CSV_XS). Note that $row is an arrayref, how to work with it is discussed in perlreftut.
#!/usr/bin/env perl use warnings; use strict; use Text::CSV; my $csv = Text::CSV->new({ binary=>1, auto_diag=>2, eol=>$/, always_quote=>1 }); open my $ifh, '<', 'NRoomch.txt' or die $!; open my $ofh, '>', 'output.txt' or die $!; while ( my $row = $csv->getline($ifh) ) { $row->[1]='P'; # your logic to modify 2nd column here $csv->print($ofh, $row); } $csv->eof or $csv->error_diag; close $ifh; close $ofh;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Replace value in the text file
by mhoang (Acolyte) on Jul 02, 2017 at 01:40 UTC | |
|
Re^6: Replace value in the text file
by mhoang (Acolyte) on Jul 03, 2017 at 03:30 UTC | |
by huck (Prior) on Jul 03, 2017 at 03:46 UTC | |
by mhoang (Acolyte) on Jul 04, 2017 at 05:32 UTC | |
by huck (Prior) on Jul 04, 2017 at 06:01 UTC | |
by mhoang (Acolyte) on Jul 05, 2017 at 02:11 UTC | |
|