I want to be able manipulate the columns individually (thus attempting array) so I am not sure how hash can help in this case.

In the case of using a hash of arrays (HoA), you can think of the arrays as named--although Perl has no such construct.

For example, running the modified script that only prints the headers and values, the following, single file was used:

ID dataS01R1 dataS01R2 dataS02R1 1 324 445 654 2 234 654 768.5 3 542.12 764 98.2

And here the script's output:

dataS02R1 654 768.5 98.2 dataS01R2 445 654 764 dataS01R1 324 234 542.12

This shows the headers (the keys) followed by the list elements.

The regex /^dataS\d\dR\d$/ matches only the column headings listed above, which have the pattern dataSnnRn, where "n" signifies a digit 0-9.

Thus, the notation @{ $hash{$key} } represents the array of elements under the heading contained in $key.

If you want to process a specific column, use eq instead of a regex, e.g., if ( $key eq 'dataS01R1' ) { ....

This may now lead back to the original, unmodified script which generates a set of files for each processed table, as you can modify the script to fit your needs.

I try running it but there's error which the script keep running without stopping.

The script executes locally as expected, given the datasets you've shared. Without knowing more about your data, it's difficult to troubleshoot the problem you're experiencing.

Hope this helps!


In reply to Re^5: How to add column into array from delimited tab file by Kenosis
in thread How to add column into array from delimited tab file by hellohello1

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.