15,10,name3 10,#####,name1 12,10,name2 5,12,name4 8,5,name4 #### my %data = ( '10517' => { 'parent' => '10516', 'start' => 1545321095, 'end' => 1545321098, 'name' => 'A' }, '10515' => { 'parent' => '10513', 'start' => 1545321091, 'end' => 1545321095, 'name' => 'B' }, '10514' => { 'parent' => '10513', 'start' => 1545321091, 'end' => 1545321095, 'name' => 'C' }, '10516' => { 'parent' => '10513', 'start' => 1545321091, 'end' => 1545321095, 'name' => 'D', }, '10511' => { 'parent' => '#####', 'start' => 1545321090, 'end' => 1545321099, 'name' => 'E' }, '10513' => { 'parent' => '10511', 'start' => 1545321091, 'end' => 1545321097, 'name' => 'F' }, ); foreach my $pid (sort(keys(%data))) { my @parent_list; my $temp_id = $pid; while (exists $data{$temp_id}) { push (@parent_list, $data{$temp_id}{name}); $temp_id = $data{$temp_id}{parent}; } my $line = join("\t|||\t",@parent_list)."\n"; print $line; } #### E F ||| E C ||| F ||| E B ||| F ||| E D ||| F ||| E A ||| D ||| F ||| E #### $VAR1 = { 'A' => { 'pid' => { '5' => 2 }, 'data' => 4 }, 'B' => { 'pid' => { '8' => 1 '12' => 3 }, 'data' => 3 }, 'C' => { 'pid' => { '9' => 3 }, 'data' => 18 }, 'D' => { 'pid' => { '3' => 3 }, 'data' => 15 }, } #### $VAR1 = { '8' => { 'parent' => '5', 'name' => 'full_B' }, '9' => { 'parent' => '5', 'name' => 'full_C' }, '5' => { 'parent' => '#####', # No parent 'name' => 'full_A' }, '10' => { 'parent' => '8', 'name' => 'full_D' }, '12' => { 'parent' => '8', 'name' => 'full_D' }, } #### ,, 5,###,full_A 8,5,full_B 9,5,full_C 10,8,full_D #### A B,A C,B,A #### $VAR1 = { '/perl/5.14.1/strict.pm' => { 'pid' => { '7302' => 1, '7287' => 1 }, 'data' => 6 }, './hello_world.pl' => { 'pid' => { '7287' => 2 }, 'data' => 4 }, './bye_world.pl' => { 'pid' => { '7302' => 2 }, 'data' => 4 }, '/some_text.txt/' => { 'pid' => { '7302' => 1, '7287' => 1 }, 'data' => 2 } }; #### $VAR1 = { '7299' => { 'parent' => '7287', 'name' => 'echo Hello World ' }, '7305' => { 'parent' => '7302', 'name' => 'echo Bye World ' }, '7302' => { 'parent' => '7287', 'name' => './bye_world.pl' }, '7287' => { 'parent' => '###', 'name' => './hello_world.pl' } }; #### ./hello_world.pl /perl/5.14.1/strict.pm,./hello_world.pl /perl/5.14.1/strict.pm,./bye.pl,./hello_world.pl ./bye_world.pl,./hello_world.pl some_text.txt,./hello_world.pl some_text.txt,./bye_world.pl,./hello_world.pl #### ,,,...,