Pacific-Design.com

    
Home Index

1. Perl5

2. List Files

Perl5 / List Files /

#!/usr/bin/perl
use strict;
use warnings;

#--------------------------------------------------------#
#  Vindicia programming challenge
#  Written by Kevin Duraj
#--------------------------------------------------------#
my $hash_ref = {};
my @file     = `ps -e l`;

foreach my $line (@file)
{
    chomp $line;
    my @array = split(/\s+/, $line);

    my $pid  = $array[3];
    my $ppid = $array[4];
    my $name = $array[12];
    $hash_ref->{$pid}->{$ppid} = $name;
}

&print_hashes($hash_ref);

#--------------------------------------------------------#
sub print_hashes
{
    my $hash_ref = shift;

    for my $key1 (keys %$hash_ref)
    {
        print "\n$key1\n";

        for my $key2 (keys %{$hash_ref->{$key1}})
        {
            print " \\_ $hash_ref->{$key1}->{$key2}\n";
        }
    }
}

#--------------------------------------------------------#
__END__