English 中文(简体)
我如何利用Perl图书馆职能,将用户名图象绘制成图?
原标题:How can I map UIDs to user names using Perl library functions?
  • 时间:2010-05-24 19:06:17
  •  标签:
  • perl
  • unix

I m 寻找一种方式,将使用Perl的用户名绘制成像(代表系统用户的单个数字)。

请不要建议<条码>greping /etc/passwd :

<><>Edit>/strong>

作为澄清,我不想寻求一种解决办法,即读/上/上/上上明了。 我认识到,在光临下,任何解决办法都将最终完成,但我正在寻求图书馆职能,为我服务。

最佳回答

标准功能getpwuid ,与同一C功能一样,根据该功能获得用户信息。 无需<代码>。

my ($name) = getpwuid(1000);
print $name,"
";

虽然最终读到<代码>/etc/passwd文档,但使用标准接口对于其他用户来说更为清楚,更不用说,它能拯救你们一些关键的中风。

问题回答

See /etc/passwd and hash the UID to signin name.

Edit:

$uid   = getpwnam($name);
$name  = getpwuid($num);
$name  = getpwent();
$gid   = getgrnam($name);
$name  = getgrgid($num);
$name  = getgrent();

如你所知,不管你是谁,该系统的电话是/etc/passwd(见,请参见

实际上,我建议根据:- 这应当奏效,用户需要独一无二。





相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签