[Melbourne-pm] 3 dimensional array inner loop sizes
Simon Taylor
simon at unisolve.com.au
Mon Jan 26 12:39:43 PST 2009
Tim Hogard wrote:
> Greetings everyone,
>
> I have a bit of a problem I can't work out.
>
> I have a process that goes through a bunch of text files and counts up
> a bunch of stats and sticks them in a 3 dimensional array:
>
> $data[$category][$row][$col]++;
>
> Now latter I want to print out the counts like:
> Cat 1
> 1 2 3
> 1 2 3
> 2 9 1
> Cat 2
> 2 3 1 3
> 1 2 3 4
>
> The outer loop is easy:
> foreach $category ( 1 .. $#data ) {
> Yet I don't wnat to do this:
> foreach $row ( 1 .. $max_row ) {
> foreach $col ( 1 .. $max_col ) {
> print $data[$category][$row][$col]++;
>
> What is the proper syntax to find out $max_row for $data[category]
> and how do I find out $max_col for $data[category][$max_row]?
> I tried things like $#data[$category] but that doesn't work.
>
> I'm using perl 5.8.8 and 5.10.
>
>
See the section "ARRAY OF ARRAYS" in perldoc perldsc.
Cheers,
Simon
More information about the Melbourne-pm
mailing list