amdevious has asked for the wisdom of the Perl Monks concerning the following question:
Hi all. I'm new to this site and also to Perl. Was wondering if I could get some guidance.
I have a csv file in the following format:I need to parse out the data to only 3 decimal places.25.484000,23.327000,.000000,27.026000,26.616000,28.414000,21.704000 47.292000,27.944000,18.266000,18.702000,4.384000,26.765000,43.507000 21.773000,28.077000,.000000,25.974000,30.354000,17.996000,7.765000 25.484000,23.327000,.000000,27.026000,26.616000,28.414000,21.704000 47.292000,27.944000,18.266000,18.702000,4.384000,26.765000,43.507000 21.773000,28.077000,.000000,25.974000,30.354000,17.996000,7.765000
I have the following code to work on the CSV file but cant get my print statements correct to truncate the numbers.
Any help would be appreciated.#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $file = '112008.csv'; my $output='112008.txt'; my $csv = Text::CSV->new(); open (CSV, "<", $file) or die $!; open(OUTFILE,">$output") || die "Can't open file $output"; while (<CSV>) { if ($csv->parse($_)) { my @columns = $csv->fields(); printf OUTFILE "@columns\n"; } else { my $err = $csv->error_input; print "Failed to parse line: $err"; } } close CSV;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Question about parsing columns when using Text::CSV
by kennethk (Abbot) on Jan 06, 2009 at 15:14 UTC | |
by Anonymous Monk on Jan 08, 2009 at 20:45 UTC | |
|
Re: Question about parsing columns when using Text::CSV
by borisz (Canon) on Jan 06, 2009 at 15:15 UTC | |
|
Re: Question about parsing columns when using Text::CSV
by Tux (Canon) on Jan 06, 2009 at 15:40 UTC | |
by jeffa (Bishop) on Jan 06, 2009 at 17:44 UTC | |
by Tux (Canon) on Jan 07, 2009 at 09:42 UTC | |
|
Re: Question about parsing columns when using Text::CSV
by fullermd (Vicar) on Jan 06, 2009 at 15:18 UTC | |
|
Re: Question about parsing columns when using Text::CSV
by eighty-one (Curate) on Jan 06, 2009 at 16:05 UTC |