Hello List,

I have almost completed my hash of a hash problem but for some reason my
data is sitting all over the place... as shown in the following hash of
a hash...


%popusers = (
              'fullname1' => {
                                'fullnam1' => 'NO'
                              },
              'user2' => {
                               'fullname2' => 'YES'
                             },
              'fullname2' => {
                              'user3' => 'NO'
                            },
              'user4' => {
                             'fullname4' => 'NO'
                           }
            );

....is ment to look like the following...

%popusers = (
              'user1' => {
                                'fullname1' => 'NO'
                              },
              'user2' => {
                               'fullname2' => 'YES'
                             },
              'user3' => {
                              'fullname3' => 'NO'
                            },
              'user4' => {
                             'fullname4' => 'NO'
                           }
            );

Here is my perl code but I can't seem to see all that much wrong with
it...

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $file = '/etc/passwd';
my $procrc = '.procmailrc';
my %popusers = view_users();

sub view_users{
    open( PASSWD, $file)     or die "$file: $!\n";
    flock(PASSWD, 2)         or die "Can't lock $file exclusively: $!";

    my (@users, %popusers);

    # Process the password file
    while (<PASSWD>) {
        my ($username, $groupid, $fullname) = (split/:/)[0, 3, 4];

        # Skip disabled accounts
        next if $username =~ /^\*/;

        # Only keep those users in group 45
        if ( $groupid == 45 ) {
            push @users, $username, $fullname;
        }
    }

    # Test each account for the existance of the ..procmailrc file
    for (1 .. (scalar @users) / 2) {
        my ($username, $fullname) = @users[$_-1, $_];

        # Perform the check
        my $exists = (-e "/home/$username/$procrc") ? ('YES') : ('NO');

        # Place the information into the hash we return
        $popusers{$username}{$fullname} = $exists;
    }

    close PASSWD             or die "$file: $!\n";
    return %popusers;
}

view_users();

print Data::Dumper -> Dump( [\%popusers], ['*popusers']);

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to