http://qs321.pair.com?node_id=865376

Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All,
Earlier today, I was faced with a problem that amounted to:
for my $let (keys %hash) { for my $num (keys %{$hash{$let}}) { for my $name (keys %{$hash{$let}{$num}}) { print join(',', $let, $num, $name, $hash{$let}{$num}{$name +}), "\n"; } } }

The trouble was, the data structure was going to be an arbitrary number of levels deep. My first inclination was to reach for Algorithm::Loops but it didn't seem like a good fit. My second idea was to write an iterator (see Arbitrarily Nested Loops) but I wanted a coworker who is just learning perl (former C++ developer) to be able to maintain it. In a few minutes, I came up with a recursive solution which surprised me.

On my way home, I thought of several other ways of doing it and I was wondering how others might solve the problem. That is my question - how would you do it? I have provided my recursive solution below to get the ball rolling.

Cheers - L~R