Hi Monks!

Suppose I have this file with 2 lines: e.g

num: C1H10 C5H30 C3H5 C2H8 amount: 1 5 6 9
And I want to create this table with Perl:
* 1-2 3-5 6-10 1-10 10 6 0 11-20 0 0 0 21-30 0 5 0

where the 1st row is the range of number that comes after 'C' and the 1st column is the range of number comes after 'H'.

So the script should check each word in the input, and put it's amount (2nd line in input file) inside the correct cell.

For example: in C5H30 i have 5 after 'C' and 30 after 'H' and its amount is 5. so, i should put 5 in cell (21-30,3-5)

Another example: I have amount of 10 in cell (1-10,1-2) because i have two such names that fit into these ranges of C and H and their total amount sums to 10 (1+9)

I'm new to Perl and its data structures, and I'm not sure how to do it but know Perl definitely can do it.

Can anyone share his thoughts ? Thanks


In reply to 2D table in perl by sirok4

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.