in reply to Re^2: TreeDumper Parser / Inverse?
in thread TreeDumper Parser / Inverse?

I kind of like this solution, but YMMV. The approach isn't much different from yours.
my @stack = ({}); while (<DATA>) { s/\s+$//; # remove trailing space and newline my $depth = 0; $depth++ while $depth < @stack && s/^[|` ][- ] //; die 'malformed input' if $depth < 1; splice @stack, $depth; my $obj = $stack[-1]; if (/^(.*?) = ?(.*)/) { $obj->{$1} = $2 eq 'undef' ? undef : $2; } elsif (s/ \(no elements\)$//) { $obj->{$_} = []; } else { push @stack, $obj->{$_} = {}; } } my $output_hash = $stack[0];