當前位置:首頁 » Perl » perl setgrent()函數

perl setgrent()函數

perl setgrent()函數例子,setgrent()函數實例代碼 - 集合(或重置)組項的設置開始枚舉的。

語法

setgrent


定義和用法

集合(或重置)組項的設置開始枚舉的。這個函數應該被調用之前第一次調用getgrent。

返回值

  • Nothing

例子

試試下麵的例子:

#!/usr/bin/perl -w
#by www.gitbook.net

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;
	
}