After a lot of help from liverpole, I think I've straightened this out. At the very least, it's giving me the output I was looking for.
Here's the final version for the curious:
which generates the following output:sub unpack_row($@); sub unpack_row($@){ my $hash = shift(@_); my @row = @_; my @stack; if(ref($hash) eq 'HASH'){ my $header = $hash->{'header'}; while(my ($key, $value) = each(%$hash)){ push(@stack, unpack_row($value, (@row, $key))); } } else { return([@row, $hash]); } return @stack; } my $hash = {}; $hash->{'foo'}->{'bar'}->{'bat'} = 5; $hash->{'foo'}->{'bar'}->{'bird'} = 2; $hash->{'goo'}->{'tab'}->{'bird'} = 2; print Dumper($hash); print Dumper(unpack_row($hash, ()));
$VAR1 = { 'goo' => { 'tab' => { 'bird' => 2 } }, 'foo' => { 'bar' => { 'bat' => 5, 'bird' => 2 } } }; $VAR1 = [ 'goo', 'tab', 'bird', 2 ]; $VAR2 = [ 'foo', 'bar', 'bat', 5 ]; $VAR3 = [ 'foo', 'bar', 'bird', 2 ];
In reply to Re^2: Recursive function always returns 0
by jpfarmer
in thread Recursive function always returns 0
by jpfarmer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |