in reply to •Re: Recursing through hash of arrays
in thread Recursing through hash of arrays

Thank you for that! At least I was on the right track with it all. And I think I'm beginning to understand a bit more about references. Just haven't got to that chapter of your book yet. :)

One other thing though. I've changed the subroutine code as you suggested to:

sub print_tree{ my ($sub, $tab) = @_; foreach (@{$found{$sub}}){ print "$tab$_\n"; $tab .= "\t"; print_tree($_, $tab); } return; }

but the spacing is still one tab off after the first run through.

I get:

a c f e b etc...

instead of:

a c f e b etc...

Any idea on why the $tab variable isn't resetting itself when the recursion starts coming back up it's chain? The e should be in the same column position as c.

Thanks!

There is no emoticon for what I'm feeling now.

Replies are listed 'Best First'.
•Re: Re: •Re: Recursing through hash of arrays
by merlyn (Sage) on Jun 24, 2003 at 18:16 UTC
    Any idea on why the $tab variable isn't resetting itself when the recursion starts coming back up it's chain?
    Yeah, you're messing with $tab in the caller, not the callee. Stop that! Don't append to the value of $tab - simply pass a different value:
    print_tree($_, "\t$tab");

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.