ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
Also consider the following structure of a paths:$VAR1 = { '15746' => { 'ppid' => '15741', 'name' => 'echo Hello World' }, '15747' => { 'ppid' => '15741', 'name' => './bye.pl' }, '15741' => { 'ppid' => 'NA', 'name' => './hello_world.pl' }, '15748' => { 'ppid' => '15747', 'name' => 'echo Bye World' } };
In the previous thread I asked your help to create a chain file for each path. The final code looks as following:$VAR1 = { 'data' => { './strict.pm' => { 'pid' => { '15747' => 1, '15741' => 1 } }, './hello_world.pl' => { 'pid' => { '15741' => 2 } }, './bye.pl' => { 'pid' => { '15747' => 2 } }, './bin-perl' => { 'pid' => { '15747' => 1, '15741' => 1 } } }, 'total' => { './strict.pm' => 6, './hello_world.pl' => 4, './bye.pl' => 4, './bin-perl' => 2 } };
Output:sub parents { my ($name,$pid,$processes_href) = @_; unless(exists($processes_href->{$pid})) { return ''; } my $secondname = $processes_href->{$pid}{name}; if ($name eq $secondname) { return parents($secondname,$processes_href->{$pid}{ppid},$proc +esses_href); } return ",".$secondname.parents($secondname,$processes_href->{$pid} +{ppid},$processes_href); } sub create_chain { my ($processes_href,$paths_href) = @_; foreach my $data (keys(%{$paths_href>{'data'}})) { while (my ($file, $procs) = each %{$data}) { foreach my $pid (keys(%{$procs->{'pid'}})) { print $fh $file.parents($file,$pid,$processes_href)."\ +n"; } } } close($fh); }
It works good but the final format is not so readable. I would like to create a format that looks like the output of the Linux command 'tree' which gets a directory and returns the recursive tree../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
For the example I gave, the output should be:tree ./regexpu-core/ |-- LICENSE-MIT.txt |-- README.md |-- data | |-- character-class-escape-sets.js | `-- iu-mappings.json |-- package.json `-- rewrite-pattern.js
At first, I have tried to find a module which does something similar but without any success. Also I tried to find some Linux command which does it but also without any success.`-- hello_world.pl |-- bin-perl |-- bye.pl | |-- bin-perl | `-- strict.pm `-- strict.pm
|
---|