Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

2D table in perl

by sirok4 (Initiate)
on Oct 27, 2012 at 10:04 UTC ( #1001181=perlquestion: print w/ replies, xml ) Need Help??
sirok4 has asked for the wisdom of the Perl Monks concerning the following question:

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

Comment on 2D table in perl
Select or Download Code
Re: 2D table in perl
by zentara (Archbishop) on Oct 27, 2012 at 10:11 UTC
Re: 2D table in perl
by ansh batra (Friar) on Oct 27, 2012 at 11:07 UTC

    can you explain how are the values coming in output?

    its not clear

      Sorry, I had some mistakes.

      I retyped them and added two examples

      Hope it's clear now !

      Thanks :)

Re: 2D table in perl
by choroba (Abbot) on Oct 27, 2012 at 15:06 UTC
    Not as short as I hoped :-)
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001181]
Approved by ansh batra
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (11)
As of 2014-09-17 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (64 votes), past polls