#!/usr/bin/perl # https://perlmonks.org/?node_id=1228107 use strict; use warnings; my $firsthash = { "./bye_world.pl" => { data => 4, pid => { 7302 => 2 } }, "./hello_world.pl" => { data => 4, pid => { 7287 => 2 } }, "/perl/5.14.1/strict.pm" => { data => 6, pid => { 7287 => 1, 7302 => + 1 } }, "/some_text.txt/" => { data => 2, pid => { 7287 => 1, 7302 => + 1 } }, }; my $secondhash = { 7287 => { name => "./hello_world.pl", parent => "###" }, 7299 => { name => "echo Hello World ", parent => 7287 }, 7302 => { name => "./bye_world.pl", parent => 7287 }, 7305 => { name => "echo Bye World ", parent => 7302 }, }; sub parents { my ($name, $pid) = @_; exists $secondhash->{$pid} or return ''; my $secondname = $secondhash->{$pid}{name}; return ($name ne $secondname and ",$secondname") . parents($secondname, $secondhash->{$pid}{parent}); } for my $name ( keys %$firsthash ) { for my $pid ( keys %{ $firsthash->{$name}{pid} } ) { print $name, parents($name, $pid), "\n"; } }

In reply to Re: Iterating through process hierarchy by tybalt89
in thread Iterating through process hierarchy by ovedpo15

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.