linux - 如何将/etc/passwd 存储在散列或数组中?

标签 linux perl

我想将 /etc/passwd 的内容存储在一个结构中,以便稍后更新每个值,但我不知道该使用哪个结构。

#!/usr/bin/perl

use warnings;
use strict;

open PASSWD, "/etc/passwd";
while(<PASSWD>) {

    chomp;
    my @f = split /:/;

    print "username $f[0]\n";
    print "password $f[1]\n";
    print "uid      $f[2]\n";
    print "gid      $f[3]\n";
    print "gecos    $f[4]\n";
    print "home     $f[5]\n";
    print "shell    $f[6]\n";
    print "--------------------------\n";

}

我假设它应该是一个哈希数组,其中用户名是键,但我不知道该怎么做。

“数组的哈希数组”是要走的路吗?

最佳答案

参见 Passwd::Unix :

ABSTRACT

Passwd::Unix provides an abstract object-oriented and function interface to standard Unix files, such as /etc/passwd, /etc/shadow, /etc/group. Additionaly this module provides environment to testing new software, without using system critical files in /etc

关于linux - 如何将/etc/passwd 存储在散列或数组中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4920995/

相关文章:

Linux命令删除.git文件夹以外的所有文件?

linux - sendmail - 具有相同的发件人和收件人主机名

Perl 与 Aspell 的接口(interface)

arrays - perl qw() 函数分配行而不是单词

linux - 在perl中拆分和过滤linux命令的输出

c++ - 在没有 Inotify 的情况下从 Linux 内核读取文件系统事件

python - linux下用python进行web开发的推荐工具?

linux - shell脚本中字符串中的单引号

java - java 中的平台相关错误(在 eclipse windows 中运行,但在 linux 中出错)

perl - 通过UDP发送数据包