in reply to Building data structure from several /etc/passwd files

Your question isn't clear at all, but I suspect that a search on CPAN for passwd will find a module that will do what you want.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: /etc/passwd
by tux242 (Acolyte) on Oct 30, 2003 at 21:56 UTC
    3/4 of the code is already written i am a newbie i just need to be able to tell all the passwd.server files each unique id are on and howto shorten the passwd.server array statement in the code given with a wildcard, if possible, so the hash array does not have to be so verbose? Thanks. Tux242
      Ok, I think we can solve both of those problems with the same thing. Try something like this:
      #!/usr/bin/perl $nf="endo"; foreach $file (@ARGV) { open (PASSWD, "$file") || die "Couldn't open $file\n"; while (<PASSWD>) { ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/); $USERS{${file}.${login}} = $gcos; #this way the first key is "passwd.server1.root" } close (PASSWD); } open (NEWFILE, ">$nf"); foreach $login (sort keys %USERS) { print NEWFILE "$login, $USERS{$login}\n"; } close (NEWFILE); # just because I'm tidy

      and now you call your script with script.pl passwd*