I, also, am confused about what is supposed to be summed while processing the file (I can't see anything numeric in your sample data). (Update: I also don't understand what you want to do with a 2D array, or why.) However, this code will produce exactly the output you specify from the given input. (Caution: The tabs that are supposed to be in the  __DATA__ section may not survive the posting process. Check and restore them as needed.)

use strict; use warnings; <DATA>; # ignore first input line while (my $line = <DATA>) { $line =~ s{ \t }{; }xmsg; # make output ProteinName field min 4 cols wide, right justified. $line =~ s{ \A ([^;]*) (?= ;) }{ sprintf '%4s', $1 }xmse; print $line; } exit; __DATA__ ProteinName MF1 MF2 MF3 GH1 Growth factor activity Growth hormone receptor binding Ho +rmone activity POMC G protein-coupled receptor binding Hormone activity Sign +aling receptor binding THRAP3 ATP binding Source Nuclear receptor transcription coactiv +ator activity Phosphoprotein binding

Update: I just round-tripped the code posted above and it looks like the tabs in the  __DATA__ section survived intact!


Give a man a fish:  <%-{-{-{-<


In reply to Re: storing a file in 2d array by AnomalousMonk
in thread storing a file in 2d 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.