Apronline has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Can you please let me know how to find a count of USER UNIX groups in perl?

Replies are listed 'Best First'.
Re: count of USER UNIX groups
by Anonymous Monk on Jan 25, 2015 at 03:11 UTC

    That's a bit vague... please see How do I post a question effectively? and perhaps you could explain a bit more about what you're trying to do and what you have tried so far.

    Anyway, if you really just want a count of the existing UNIX groups, see getgrent (note: apparently the online doc for this version isn't showing up, but try the command perldoc -f getgrent), here's one quick way:

    my $count = 0; $count++ while defined getgrent; print "$count\n";
      Sorry for the confusion! "groups $USER" in unix---> gives list of my unix groups. How can we get our unix groups list and count in perl? Thanks!

        A brief google leads to this node, which deals with listing a user's secondary groups, you can adapt the answers from there to suit your needs. The primary group of a user can be retrieved with getpwent. You may also want to use User::pwent and User::grent for a nicer interface to those functions.

A reply falls below the community's threshold of quality. You may see it by logging in.