Dear Monks,
I do not program Perl very often, and if I do it is mainly on a line by line basis.
I'm often running into issues when I have to manipulate data across columns. What I need currently is to stack columns of a table onto each other. My data looks like:
foo1 1 4 7
foo2 2 5 8
foo3 3 6 9
And I need it in
foo1 1
foo2 2
foo3 3
foo1 4
foo2 5
foo3 6
foo1 7
foo2 8
foo3 9
That is, in column one are the identifiers, and the numbers following from the 2nd column are its values. Obviously I have to read in the whole table and then print column one followed by its values in column 2, then print column 1 again, followed by its values in column 3, and so forth. After some searching it seems that I need to build a hash of arrays, and from that call the data from a loop? However, as I said, I usually do text manipulations line by line, and what I found so far was rather confusing.
I hope someone can help me here.
Cheers,
Robert
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.