topaz has asked for the wisdom of the Perl Monks concerning the following question:

Ok let me ask the question again, I dont think I was clear enough in explaining what I need :( I have a list of $a $b values which can go from (-180 --- 180)

For example: 100 2 -2 44 332 9 26 -4 332 9 0 -1

I want to creat a 2 dimentional array 360x360 and set it to zero then start recording the count of combnation $a $b the combanation of 332 and 9 appered twice on the list so the count will be 2

my @a = ((0) x 361); my @b = ((0) x 361); my @matrix = (@a,@b) while ($line = <IN>) { @record = split(/\s+/, $line); $a = $record[0]; $b = $record[1]; @matrix [$a+180][$b+180] ++; }
and Yes Ikegami you are right I do understand now why 361 :) thanks

Replies are listed 'Best First'.
Re: 2 dimensional array
by ikegami (Patriarch) on Jul 28, 2011 at 19:43 UTC
    Original content of parent
    Hi,

    I have a list of 2 variable $a $b $a can be from -180 up to 180 $b also can be from -180 up to 180 I want to create a 360 x 360 array and fill it with zeros then go throw the list and record the counts of the combination of $a and $b (i.e. every time I find a combination of 2 4 I will add +1 to the count)

    For example a list of:

    3 0 1 2 2 4 3 0 3 3 2 4 0 1 2 3 4 0 0 0 0 2 0 1 0 0 0 0 0 2 0 1 0 0 0 3 0 0 0 1 0 4 0 0 2 0 0

    Could you please help me? I don’t know how to start :s

    Thx

    I think you mean 361 x 361. Arrays must have non-negative indexes, so just store everything 180 indexes higher.

    $a[$row][$col]
    becomes
    $a[$row + 180][$col + 180]
Re: 2 dimensional array
by ww (Archbishop) on Jul 28, 2011 at 22:25 UTC
    "Ok let me ask the question again...."

    We're always glad to have clarification of a question, but please, do so by editing (using <strike>...</strike>) and appropriate labeling to indicate what's new (if it's changed, we can tell from your strikeouts).

    But, please, don't start a new thread (create a new rootnode) to correct or clarify. Often as not, that merely confuses readers as to which thread you really care about.

      i do apologies for that, it is my first time. Many thanks for clarification