Thanks Ken, for bringing up getpwent. BTW, i used the other approach which did not mention getpwent, but still the job was done, by the code below :
my $HAN = "handle";
my $FILE = "passwd.txt";
open("$HAN", "$FILE")||die "Error opening file: $!\n";
while(<$HAN>) {
my ($name,$passwd,$uid,$gid,$gcos,$dir,$shell) = split(/:/,$_);
print "UID is: $uid\n";
print "GID is: $gid\n";
}
close("$HAN");
| [reply] [d/l] |
"Thanks Ken, for bringing up getpwent. BTW, i used the other approach which did not mention getpwent, but still the job was done, ..."
You're welcome. I'm glad you found a working solution.
For future reference, all of that code could have been replaced by:
while (my @pw = getpwent) {
printf "UID is: %s\nGID is: %s\n", @pw[2,3]
}
By the way, take a look at open for better ways of doing: open("$HAN", "$FILE")
| [reply] [d/l] [select] |