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


Perl setgrent用法及代碼示例



描述

此函數將枚舉設置(或重置)到組條目集的開頭。這個函數應該在第一次調用 getgrent 之前調用。

用法

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

setgrent

返回值

此函數不返回任何值。

示例

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

#!/usr/bin/perl -w

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

setgrent();    # Set the beginnging of the group database;

print "Again reading /etc/passwd file\n";
while( ($name,$passwd,$gid,$members) = getgrent() ) {
   print "Name  = $name\n";
   print "Password  = $passwd\n";
   print "GID  = $gid\n";
   print "Members  = $members\n";
}

endpwent;  #claose the database;

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

Name  = root
Password  = x
GID  = 0
Members  = root
Name  = bin
Password  = x
GID  = 1
Members  = root bin daemon
Name  = daemon
Password  = x
GID  = 2
Members  = root bin daemon
Name  = sys
Password  = x
GID  = 3
Members  = root bin adm
Name  = adm
Password  = x
GID  = 4
Members  = root adm daemon
.
.
.
Name  = kvm
Password  = x
GID  = 36
Members  = qemu
Name  = qemu
Password  = x
GID  = 107
Members  = 
Name  = com
Password  = x
GID  = 501
Members  = 
Name  = webgrp
Password  = x
GID  = 502
Members  = com
Name  = railo
Password  = x
GID  = 495
Members  = 

相關用法


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