in reply to TreeDumper Parser / Inverse?

Some quick testing reveals that it's not always possible to reconstruct the exact input unambiguously. Because of this, the usefulness of a CPAN module is questionable. You might be able to put together something that works well enough with the data you have, though.
use Data::TreeDumper; $Data::TreeDumper::Displayaddress = 0; print DumpTree({ a => "z\n", b => "z[\\n]", 'c = d' => 'e = f', }); __END__ |- a = z[\n] |- b = z[\n] `- c = d = e = f

Replies are listed 'Best First'.
Re^2: TreeDumper Parser / Inverse?
by jimpudar (Pilgrim) on Aug 14, 2017 at 20:54 UTC
    For the record, here is the code I am using which works well enough for my purposes. Thanks again to everyone for the responses.
    sub untree { my $lines = shift; my %obj; my @stack; foreach (@$lines) { /([|`][-])/; my $key_level = $-[0] / 3; if ( $key_level < @stack ) { pop @stack until $key_level == @stack; } my $current = \%obj; $current = $current->{$_} foreach @stack; if (/(\w+)\s=\s(\w*)\s*$/) { $current->{$1} = $2 eq 'undef' ? undef : $2; } elsif (/(\w+)\s\(no\selements\)/) { $current->{$1} = []; } elsif (/(\w+)\s=\s*$/) { $current->{$1} = ''; } elsif (/(\w+)\s*$/) { push @stack, $1; $current->{$1} = {}; } } return \%obj; }
Re^2: TreeDumper Parser / Inverse?
by jimpudar (Pilgrim) on Aug 09, 2017 at 15:21 UTC
    Ah, very good point. This type of data I had not considered. Thanks!