aardvark has asked for the wisdom of the Perl Monks concerning the following question:
Does anybody know of a better way to do this?sub read_passwd { open IN, '/etc/passwd' or die "can't open IN $!\n"; my %users; my @fields = qw(name pword uid gid fullname home shell); while (<IN>) { chomp; my %rec; my @data = split(/:/); $rec{$fields[0]} = $data[0]; $rec{$fields[1]} = $data[1]; $rec{$fields[2]} = $data[2]; $rec{$fields[3]} = $data[3]; $rec{$fields[4]} = $data[4]; $rec{$fields[5]} = $data[5]; $rec{$fields[6]} = $data[6]; $users{$rec{name}} = \%rec; } return (\%users); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(dkubb) Re: (2) Parsing the /etc/passwd file
by dkubb (Deacon) on Feb 19, 2001 at 07:24 UTC | |
|
Re: assigning to a hash via split
by danger (Priest) on Feb 19, 2001 at 06:48 UTC | |
|
Re: assigning to a hash via split
by japhy (Canon) on Feb 19, 2001 at 06:49 UTC | |
|
Re: assigning to a hash via split
by BlueLines (Hermit) on Feb 19, 2001 at 07:19 UTC | |
by japhy (Canon) on Feb 19, 2001 at 08:11 UTC |