G'day shabird,

"How can i achieve my desired result?"

You could try the sum0 function from the core List::Util module.

This code:

#!/usr/bin/env perl use strict; use warnings; use List::Util 'sum0'; my (@all_data, @sum_data); while (<DATA>) { next if $. == 1; push @all_data, [split]; } print "All (original) data:\n"; print "@$_\n" for @all_data; for (@all_data) { push @sum_data, [$_->[0], sum0 @$_[1 .. $#$_]]; } print "\nSummary data:\n"; print "@$_\n" for @sum_data; __DATA__ GeneID Tp1 Tp2 Tp3 ALA1 10 12 11 THR8 57 99 12 HUA4 100 177 199 ABA5 2 5 10

Produces this output:

All (original) data: ALA1 10 12 11 THR8 57 99 12 HUA4 100 177 199 ABA5 2 5 10 Summary data: ALA1 33 THR8 168 HUA4 476 ABA5 17

— Ken


In reply to Re: Query of multi dimentional array by kcott
in thread Query of multi dimentional array by shabird

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.