Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: /etc/passwd

by pzbagel (Chaplain)
on Oct 30, 2003 at 22:16 UTC ( [id://303434]=note: print w/replies, xml ) Need Help??


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

How about some <> magic:

#! /usr/bin/perl #Call the scripts with <scriptname> passwd.* while (<>) { ($login, $passwd, $uid, $gid, $gcos, $home, $shell) = split(/:/); $USERS{$login} = $gcos; } $nf="endo"; open (NEWFILE, ">$nf"); foreach $login (sort keys %USERS) { $gcos = $USERS{$login}; print NEWFILE "$login, $gcos\n"; }

Now just call the script with the passwd files as arguments(or even with passwd.*). The <> in the while will automatically open each file in turn and read it in for you. I also moved the opening of NEWFILE to the end of the script since that's when you actually have to have it open.

Later

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://303434]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found