in reply to How do I set up the recursion?

Well, you've got several problems with that. I almost don't know where to start... what stood out to me immediately was that you are making your deparse function return different types of things at different times. Here it is supposed to return a key, there it is supposed to return a reference to your file-scoped %Config variable, and over here and here it is supposed to just return; (which is the same as returning undef or, in list context, an empty list.)

The core issue is that this probably isn't the right place to try to use recursion. Recursion is great where the the data structure itself is recursive. Yours isn't because different levels within the structure contain data that is used for different purposes. Your elements aren't homogenous.

Just use an iterative approach to parsing it. It is much more straight forward. Here's my quick try at intrepreting your intentions:

sub deparse { my $tree = shift; my $deparsed = {}; for my $aref (@$tree) { for my $section (@$aref) { my $hash = $deparsed->{$section->[0]} = { }; # $hash is a +shortcut for my $aref (@{$section->[1]}) { $hash->{$aref->[0]} = [ $aref->[1] ]; if (my $comment = $aref->[2]) { $comment =~ s/^\s+[;#]//; push @{$hash->{$aref->[0]}}, $comment; } } } } return $deparsed; }
Since some of your array refs seem to be useless containers, you might be able to get away with fewer levels of nested fors. If it were my project, I'd almost certainly try to make it a bit shallower...

-sauoq
"My two cents aren't worth a dime.";