Your request would be clearer, if you had used code tags. see How do I post a question effectively?.

My suggestion:

#! /usr/bin/perl -l use strict; use warnings; my %sum_of; # read linewise from filehandle while ( my $line = <DATA> ) { # remove linebreak; for details, see: perldoc -f chomp chomp $line; # split at whitespace characters; see: perldoc -f split # change \s to \t if only tabs are allowed; # remove + from pattern, if only one whitespace separates the column +s my ( $name, @fields ) = split m{\s+}, $line; # support multiple columns; sum up the fields per column for my $idx ( 0 .. $#fields ) { # create a Hash of Arrays and store the sums; see: perldoc perldsc $sum_of{ $name }->[$idx] += $fields[$idx]; } } # print result for my $name ( keys %sum_of ) { print join "\t", $name, @{ $sum_of{$name} }; } # __DATA__ AA 12 bb 34 AA 76 cc 98 dd 76 bb 98

update


In reply to Re: find unique elments and sum the corresponding values by linuxer
in thread find unique elments and sum the corresponding values by Prl_learner

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.