in reply to Converting hash structure into a special tree
#!/usr/bin/perl # https://perlmonks.org/?node_id=1228464 use strict; use warnings; local $_ = join '', sort map "$_\n", map {join ',', reverse split /,/ +} map s/\.\/|\n//gr, <DATA>; sub transpose { my $tmp = ''; $tmp .= "\n" while s/^./ $tmp .= $&; '' /gem; $_ = $tmp; } my @p = map quotemeta, /[^,\s]+/g; my $lead = do { local $" = '|'; qr/(@p)/ }; 1 while s/^[-| ]*\K$lead,/|-- /m; my $line = ''; $line |= $_ for /.+/g; my $length = length $line; s/.+/ sprintf "%-${length}s", $& /ge; transpose; s/\|*\K\|/`/g; transpose; s/ +$//gm; s/--(?= [|`])/ /g; s/^/ /gm; s/ /`-- /; print; __DATA__ ./strict.pm,./hello_world.pl ./strict.pm,./bye.pl,./hello_world.pl ./hello_world.pl ./bye.pl,./hello_world.pl ./bin-perl,./hello_world.pl ./bin-perl,./bye.pl,./hello_world.pl
Outputs:
`-- hello_world.pl |-- bin-perl |-- bye.pl | |-- bin-perl | `-- strict.pm `-- strict.pm
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting hash structure into a special tree
by bliako (Abbot) on Jan 13, 2019 at 20:35 UTC | |
by LanX (Saint) on Jan 14, 2019 at 00:08 UTC | |
|
Re^2: Converting hash structure into a special tree
by ovedpo15 (Pilgrim) on Jan 13, 2019 at 23:26 UTC | |
by ovedpo15 (Pilgrim) on Jan 13, 2019 at 23:55 UTC | |
by tybalt89 (Monsignor) on Jan 14, 2019 at 00:33 UTC | |
by ovedpo15 (Pilgrim) on Jan 14, 2019 at 00:50 UTC | |
by tybalt89 (Monsignor) on Jan 14, 2019 at 02:05 UTC | |
|