- Perl 基础知识
- Perl - 主页
- Perl - 简介
- Perl - 环境
- Perl - 语法概述
- Perl - 数据类型
- Perl - 变量
- Perl - 标量
- Perl - 数组
- Perl - 哈希
- Perl - IF...ELSE
- Perl - 循环
- Perl - 运算符
- Perl - 日期和时间
- Perl - 子例程
- Perl - 参考资料
- Perl - 格式
- Perl - 文件 I/O
- Perl - 目录
- Perl - 错误处理
- Perl - 特殊变量
- Perl - 编码标准
- Perl - 正则表达式
- Perl - 发送电子邮件
- Perl 高级
- Perl - 套接字编程
- Perl - 面向对象
- Perl - 数据库访问
- Perl - CGI 编程
- Perl - 包和模块
- Perl - 流程管理
- Perl - 嵌入式文档
- Perl - 函数参考
- Perl 有用资源
- Perl - 问题与解答
- Perl - 快速指南
- Perl - 有用的资源
- Perl - 讨论
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_function_references.htm