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:
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 need to parse out the data to only 3 decimal places.

I have the following code to work on the CSV file but cant get my print statements correct to truncate the numbers.

#!/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;
Any help would be appreciated.

In reply to Question about parsing columns when using Text::CSV by amdevious

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.