Perl functions references-getpwuid Function - Perl Scripting

what is the getpwuid function?What is its syntax?


This function returns a list of fields in list context, as extracted from the /etc/passwd file, based on the user name specified by EXPR. It.s generally used like this −
($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) = getpwuid ($uid);
In a scalar context, returns the user name. If you are trying to access the whole /etc/passwd file, you should use the getpwent function. If you want to access the details by user name, use getpwnam.


Following is the simple syntax for this function −

Return Value

This function returns user Name in scalar context and user record (name, password, user ID, group ID, quote, comment, real name, home directory, shell) in list context.


Following is the example code showing its basic usage −
When above code is executed, it produces the following result −

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Perl Scripting Topics