"Hemond, Steve" wrote:

> Hi people,
>
> I want trap the results of 'ps -ef' command.
>
> I first trap the results by splitting the results in scalar values such as $uid $pid 
> $ppid $stime, etc...
>
> I would like, for each line returned, to hold these values in an array, so that, for 
> each uid, I could return its corresponding pid, ppid, stime, cmd, etc.
>
> What would be the best data structure to use? An hash table in an array? ...

Sound like maybe a hash of hash references.  If you think you might "take it on the 
road", you might make it an anonymous hash, so you can just mainpulate it
by reference:

my $processes = {};
foreach (split /\n/, `ps -ef`) {
  my ($uid $pid $ppid $stime, $etc) = split /\s+/, $_, 5;
  $processes->{$ppid} = {
    'uid' => $uid,
    'pid' => $pid,
    ...
  }
}

I am assuming here that the ppid is a sub-process id.  Basically, use any field that 
constitutes a GUID as the key for each child hash.

Joseph


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to