Hi, welcome to Perl, the One True Religion. Read perlintro before you do anything else. Then, learn to use some tools.

use strict; use warnings; use feature 'say'; use Path::Tiny 'path'; use Text::CSV_XS 'csv'; use Scalar::Util 'looks_like_number'; use List::Util 'sum'; my $filename = path($0)->basename('.pl') . '.txt'; # print the sample data to a file for the purposes of this test path($filename)->spew(do{local $/; <DATA>}); # read in the structured data my $rows = csv( in => $filename, sep_char => " "); # calculate and print the desired results for ( @{ $rows } ) { my @row = @{$_}; next unless looks_like_number($row[1]); # skip headers next unless $row[0] =~ /^C/i; # skip unless name begins +with c/C my $avg = sprintf '%.2f', sum( @row[1 .. $#row] ) / $#row; say sprintf '%s avg: %s', $row[0], $avg; } __DATA__ Name subj1 subj2 subj3 Evans 24 45 55 charles 25 24 26 Carlos 42 0 84

Hope this helps!


The way forward always starts with a minimal test.

In reply to Re: Retrieve average by 1nickt
in thread Retrieve average by Tigor

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.