Perl getpwuid() 和 getpwnam()
我正在学习perl的*nix系统工具,我已经盯着下面两句话看了几分钟:
您可以将 getpwuid() 和 getpwnam() 运算符视为随机访问——它们通过键获取特定条目,因此您必须有一个键才能开始。访问密码文件的另一种方法是顺序访问——以某种明显随机的顺序抓取每个条目。
我 99% 确信这是一个拼写错误,但如果不是,我显然错过了一个关键想法。谁能解释一下这个问题?
提前致谢。
I'm learning perl's *nix system tools and I've been staring at the following two sentences for several minutes:
You can think of getpwuid() and getpwnam() operators as random access -- they grab a specific entry by key so you have to have a key to start with. Another way of accessing the password file is sequential access -- grabbing each entry in some apparently random order.
I'm 99% sure this is a typo, but if it isn't I'm clearly missing a key idea. Can anyone shed some light on the subject?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是错别字,但措辞非常糟糕。
getpwuid
通过 UID 查找 passwd 条目。getpwnam
按名称查找密码条目。这些都是“随机访问”,就像系统内存是“随机访问”一样;您可以通过提供密钥来选择您想要的一个。 (对于系统内存,“键”是地址。对于getpwuid
,键是 UID。对于getpwnam
,键是名称。)这些是对比到
getpwent
,它只是返回 passwd 文件中的“下一个”条目。条目将以某种未指定的顺序返回。这就是“顺序访问”,就像从磁盘读取文件一样。尽管对于getpwent
您不知道结果将按什么顺序出现。措辞令人困惑,因为他们使用“随机”一词来表示“随机访问”(如内存)和“明显随机顺序”(它们的意思是“未指定的顺序”)。
他们应该说“未指定的顺序”或“不确定的顺序”,而不是“明显随机的顺序”。
Not a typo, but very poorly worded.
getpwuid
looks up a passwd entry by UID.getpwnam
looks up a password entry by name. These are "random access" like system memory is "random access"; you can pick which one you want by providing a key. (For system memory, the "key" is the address. Forgetpwuid
, the key is the UID. Forgetpwnam
, the key is the name.)These are in contrast to
getpwent
, which simply returns the "next" entry from the passwd file. The entries will be returned in some unspecified order. This is "sequential access", like reading a file from disk. Although forgetpwent
you do not know what order the results will appear.The wording is confusing because they use the word "random" for both the phrase "random access" (like a memory) and "apparently random order" (by which they mean "unspecified order").
They should have said "unspecified order" or "indeterminate order" rather than "apparently random order".