當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Perl getgrgid用法及代碼示例



描述

此函數按組 ID 查找組文件條目。在列表上下文中返回以下內容 -

($name, $passwd, $gid, $members)

$members 標量包含作為組成員的登錄名的空格分隔列表。返回標量上下文中的組名。有關檢索整個組文件的更有效方法,請參閱 getgrent。在 Windows 下,考慮使用 Win32API::Net 模塊。

用法

以下是此函數的簡單語法 -

getgrgid GID

返回值

此函數返回在標量上下文中它返回組名稱和列表上下文(名稱、密碼、組 ID 和成員列表。

示例

以下是顯示其基本用法的示例代碼 -

#!/usr/bin/perl

while( ($name,$passwd,$gid,$members) = getgrent() ) {
   ($name,$passwd,$gid,$members) = getgrgid $gid;
   print "Name  = $name\n";
   print "Password  = $passwd\n";
   print "GID  = $gid\n";
   print "Members  = $members\n";
}

執行上述代碼時,會產生以下結果 -

Name  = root
Password  = x
GID  = 0
Members  = 
Name  = bin
Password  = x
GID  = 1
Members  = 
Name  = daemon
Password  = x
GID  = 2
Members  = 
Name  = sys
Password  = x
GID  = 3
Members  = 
Name  = adm
Password  = x
GID  = 4
Members  = 
Name  = tty
Password  = x
GID  = 5
Members  = 
Name  = disk
Password  = x
GID  = 6
Members  = 
Name  = lp
Password  = x
GID  = 7
Members  = 
.
.
.
.
Name  = apache
Password  = x
GID  = 48
Members  = 
Name  = rexx
Password  = x
GID  = 1001
Members  = 
Name  = objc
Password  = x
GID  = 1002
Members  = 

相關用法


注:本文由純淨天空篩選整理自 Perl getgrgid Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。