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
|
|---|