For a large number of columns in a tab-delimited or a csv file, its quite easy to use existing modules to get the information you want. If files are nicely structured, regardless of the number of columns, you can use the Data::CTable module. When combined with the Statistics::Descriptive module, you can get much more information from your data... the let's say your data is like this...
name,date,size name1,date1,120 name2,date2,140 name3,date3,150
well here's some code, hopefully easy enough to understand...
use strict; use Data::CTable; use Statistics::Descriptive; my $data = Data::CTable->new("data.txt"); # your csv file $data->clean_ws(); # clean up whitespace my $sizecolumn = $data->col('size'); # get column by name my $stat = Statistics::Descriptive::Full->new(); $stat->add_data($sizecolumn); print "sum of the column size:", $stat->sum() , "\n";
Its up to you, you can use the Statistics::Descriptive module to get much more information (sum, mean, median standard deviation etc) from your data as well, or maybe if you just need a simple sum you can add the elements of the array yourself.

perliff

----------------------

-with perl on my side


In reply to Re: Counting items in a CSV by perliff
in thread Counting items in a CSV by zyzzogeton

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.