in reply to storing a file in 2d array

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: storing a file in 2d array
by jo37 (Curate) on May 01, 2020 at 11:35 UTC
    (Caution: The tabs that are supposed to be in the __DATA__ section may not survive the posting process. Check and restore them as needed.)

    Seems to depend on how you copy the text. When using the download link, everything looks fine. As I copied the data from the OP without altering anything, I didn't even think about a possible issue with tabs.

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$