in reply to To get the secondary groups for linux

This version eliminates the unless statement, but is basically the same as your example (you should use strict). I'm running this on a Solaris 8.0 system but I don't get any duplicates.
use strict; my @sec_gp; my $name = "xxxxx"; while (my ($gname,$gpasswd,$gid,$members)=getgrent) { my @list_members=split (/\s+/,$members); my @list=grep (/$name/,@list_members); if ($list[0] eq $name) { push (@sec_gp,"$gname"); } } print "\@sec_gp: "; print "$_\n" foreach @sec_gp;
Output:
@sec_gp: acad libsoftwrite helpdesk codes

--Jim Update: The above was hastily done. Better is the following (still room for improvement I'm sure):

push(@sec_gp, "$gname") if $list[0] eq $name;
for the original if statement.

Replies are listed 'Best First'.
Re: Re: To get the secondary groups for linux
by tbo (Scribe) on Jan 08, 2002 at 14:46 UTC
    I have understand why I have duplicatas : a NIS server is running. So, now I know that the function getgrent looks both /etc/passwd and the NIS database. It doesn't appear in the french man page of getgrent (Mandrake). PS : I've got to learn english before learning Perl !