in reply to 3d arrays

Thank you all again for your help thus far. I'm certainly beginning to understand a little more about perls more complicated data structures.
What I think I actually need is a way of populating the hash/array ...
The program in question is fed a text file on the command line. This text file has all the co-ordinates as follows:
10.7 87.5
34.8 90.0
etc ...
So, what I need to do is to first collect together the number of times say that there is a bean at co-ordinates x=10.7 and y=87.5 and then print them off like I mentioned before at the end
10.7 87.5 5 for example
Again, any advice much appreciated. :)

Replies are listed 'Best First'.
Re^2: 3d arrays
by Roy Johnson (Monsignor) on Apr 08, 2005 at 15:34 UTC
    So the input is unordered, each line indicates one bean at the location given, and you just want to tally them up and then print them out in grid order? Sounds like:
    my %beancounts; while (<>) { my ($x, $y) = split; ++$beancounts{$x}{$y}; } for my $x (sort {$a <=> $b} keys %beancounts) { for my $y (sort {$a <=> $b} keys %{$beancounts{$x}}) { print "$x $y $beancounts{$x}{$y}\n"; } }

    Caution: Contents may have been coded under pressure.