in reply to Nested Loops vs Good programming

I don't know about your stated problem, but your loops have an off-by-one error:

my $count = @{ $doc->{$sub1} }; print "\n$sub1\t"; for (my $i=0; $i <= $count; $i++) {

Should be:

my $count = $#{ $doc->{$sub1} }; print "\n$sub1\t"; for my $i ( 0 .. $count ) {

The same applies to $count2 and $count3.

Replies are listed 'Best First'.
Re^2: Nested Loops vs Good programming
by ikegami (Patriarch) on Nov 14, 2008 at 20:05 UTC
    $count is a misnomer in your new code. If you change what a variable contains, you need to change its name too.

    Minimal fix (<=<):

    my $count = @{ $doc->{$sub1} }; for (my $i=0; $i<$count; $i++)

    Easier to read:

    my $count = @{ $doc->{$sub1} }; for my $i ( 0 .. $count-1 )

    Alternative:

    my $last = $#{ $doc->{$sub1} }; for my $i ( 0 .. $last )