gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:14:03 24 4
gpt4 key购买 nike

我想将 /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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com