in reply to Question about dereferencing multi-dimensional array/hash

You said that the code is working fine as is, but I'm having difficulty understanding how this is possible when you have unmatched open parentheses on the line you are asking about and this line:
my ($first_key, $first_val) = each(%{$main_hash{$k}[$x]};

One other thing that stands out to me... The following line lets the loop go one iteration too many. You should use $x instead of $x + 1:

last if ($x + 1 >= scalar(@{$main_hash{$k}});
Try changing these and let me know if anything changes.

Replies are listed 'Best First'.
Re^2: Question about dereferencing multi-dimensional array/hash
by jokerzy (Initiate) on Jun 18, 2012 at 05:36 UTC
    Hello, please refer above for the corrected version. Regarding the other thing that you mentioned, nope, I think I need  $x+1, that is because when I reach the last item in the array, I want to exit the inner 'for loop', if not  my ($next_key, $next_val) = each(%{$main_hash{$k}[$x+1]}); would give me 'Uninitialized values' errors.