in reply to Question about parsing columns when using Text::CSV
In order to start programming defensive and safe, don't use the diamond for CSV
use strict; use warnings; use Text::CSV; my ($file, output) = ("112008.csv", "112008.txt"); my $csv = Text::CSV->new ({ binary => 1 }); open my $ih, "<", $file or die "Can't open in file $file: $!"; open my $oh, ">", $output or die "Can't open out file $output: $!"; while (my $row = $csv->getline ($ih)) { my @columns = map { sprintf "%.3f", $_ } @$row; # do something with @columns print { $oh } join "|", @columns, "\n"; } $csv->eof () or $csv->error_diag (); close $ih or die "$file: $!"; close $oh or die "$output: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question about parsing columns when using Text::CSV
by jeffa (Bishop) on Jan 06, 2009 at 17:44 UTC | |
by Tux (Canon) on Jan 07, 2009 at 09:42 UTC |