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;
In reply to Question about parsing columns when using Text::CSV by amdevious
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |