Hello Monks, hope you all are fine

I am struggling with multi dimensional array this time so basically the question goes like this, I have a file which has a data like this

GeneID Tp1 Tp2 Tp3 ALA1 10 12 11 THR8 57 99 12 HUA4 100 177 199 ABA5 2 5 10

So i have read the file and assigned it to multi dimensional array with the help of this code.

my @content = (<FH>); close(FH); my $no_of_seq = scalar(@content); my @myArray; foreach my $row (@content) { my @columns = split(/\s+/,$row); push(@myArray,\@columns); # print "@columns"; } for($row = 0; $row < $no_of_seq; $row++){ for($col = 0; $col < $no_of_seq; $col++){ print($myArray[$row][$col], "\t"); } print("\n"); }

so this code prints every element in the same order but now i want to calculate the sum of numbers in each row and print that sum next to gene name i.e sum of values for ALA1 is 33 and sum of values for THR8 is 168 and so on. Now i have tried something like this.

for($row = 0; $row < $no_of_seq; $row++){ for($col = 0; $col < $no_of_seq; $col++){ $sum = $myArray[$row][$col] + $myArray[$row]; print($sum, "\t"); }

But this is printing something like this

140526414289424 140526414289424 140526414289424 1405264142894 +24 140526414289424 140526414212840 140526414212850 140526414212852 1405264142128 +51 140526414212840 140526414213296 140526414213353 140526414213395 1405264142133 +08 140526414213296 140526414288368 140526414288468 140526414288545 1405264142885 +67 140526414288368 140526414313944 140526414313946 140526414313949 1405264143139 +54 140526414313944

How can i achieve my desired result? thank you in advance


In reply to 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.