I'm trying to fully understand references so I created a data structure to
stores the output of users on my system who share home dirs.
I use a HoH to represent this data set but its not working as expected.
Conceptually I can visualize how the data should look but I cant get the
output any assistance will be appreciated thanks.
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
my $file = '/etc/passwd';
my $hash;
my ($user, $homeDir);
my $count=0;
open(my $fh, "<", $file) or die("Fatal error unable to read $file: $!");
while(<$fh>) {
next if /^#/;
($user, $homeDir) = (split /:/,$_)[0,5];
$hash->{$homeDir} = $user;
}
print Dumper($hash);
My output looks like the following:
$VAR1 = {
'/var/imap' => '_cyrus',
'/var/empty' => '_unknown',
'/Library/WebServer' => '_www',
'/var/xgrid/agent' => '_xgridagent',
'/var/virusmails' => '_amavisd',
'/var/spool/cups' => '_lp',
'/var/pcast/agent' => '_pcastagent',
'/var/root' => 'daemon',
'/var/spool/postfix' => '_postfix',
'/var/teamsserver' => '_teamsserver',
'/var/pcast/server' => '_pcastserver',
'/var/xgrid/controller' => '_xgridcontroller',
'/var/spool/uucp' => '_uucp'
};
If I replace line 13 with the following the data structure looks some what
like what I wanted but it still not correct.
$hash->{$homeDir}->{$user} = 0; basically the value 0.
$VAR1 = {
'/var/imap' => {
'_cyrus' => 0
},
'/var/empty' => {
'_spotlight' => 0,
'_appserver' => 0,
'_ard' => 0,
'_appowner' => 0,
'_mcxalr' => 0,
'nobody' => 0,
'_qtss' => 0,
'_securityagent' => 0,
...
...
...
--
[ Rodrick R. Brown ]
http://www.rodrickbrown.com http://www.linkedin.com/in/rodrickbrown