- 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 setpwent 函数
描述
此函数将枚举重新设置到一组密码项的开头。在首次调用 getpwent 前应该调用此函数。
语法
以下是此函数的简单语法 -
setpwent
返回值
此函数不返回任何值。
示例
以下是展示其基本用法示例代码 -
#!/usr/bin/perl while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent()) { print "Name = $name\n"; print "Password = $passwd\n"; print "UID = $uid\n"; print "GID = $gid\n"; print "Quota = $quota\n"; print "Comment = $comment\n"; print "Gcos = $gcos\n"; print "HOME DIR = $dir\n"; print "Shell = $shell\n"; } setpwent() ; # Rewind the databse /etc/passwd while(($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwent()) { print "Name = $name\n"; print "Password = $passwd\n"; print "UID = $uid\n"; print "GID = $gid\n"; print "Quota = $quota\n"; print "Comment = $comment\n"; print "Gcos = $gcos\n"; print "HOME DIR = $dir\n"; print "Shell = $shell\n"; } endpwent(); # Closes the database;
执行上述代码时,会产生以下结果 -
Name = root Password = x UID = 0 GID = 0 Quota = Comment = Gcos = root HOME DIR = /root Shell = /bin/bash Name = bin Password = x UID = 1 GID = 1 Quota = Comment = Gcos = bin HOME DIR = /bin Shell = /sbin/nologin Name = daemon Password = x UID = 2 GID = 2 Quota = Comment = Gcos = daemon HOME DIR = /sbin Shell = /sbin/nologin . . . Name = qemu Password = x UID = 107 GID = 107 Quota = Comment = Gcos = qemu user HOME DIR = / Shell = /sbin/nologin Name = com Password = x UID = 501 GID = 501 Quota = Comment = Gcos = HOME DIR = /home/com Shell = /bin/bash Name = railo Password = x UID = 497 GID = 495 Quota = Comment = Gcos = HOME DIR = /opt/railo Shell = /bin/false
perl_function_references.htm
广告