I'm looking for a way of mapping a uid (unique number representing a system user) to a user name using Perl.
Please don't suggest grep
ing /etc/passwd :)
Edit
As a clarification, I wasn't looking for a solution that involved reading /etc/passwd explicitly. I realize that under the hood any solution would end up doing this, but I was searching for a library function to do it for me.
The standard function getpwuid
, just like the same C function, gets user information based on its ID. No use
s needed:
my ($name) = getpwuid(1000);
print $name,"\n";
Although it eventually reads /etc/passwd
file, using standard interfaces is much more clear for other users to see, let alone it saves you some keystrokes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With