trek1s has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

How can I get the owner name (not only uid) of a file with perl? With stat() function I can retrieve both uid and gid but not the user name, so before starting to reinvent the wheel I'd like to know if there is a simpler way.

Thanks in advance.

Solution: $owner = getpwuid((stat($file))[4]);

Replies are listed 'Best First'.
Re: How to get file owner name?
by moritz (Cardinal) on Sep 10, 2007 at 08:55 UTC
    I never used it, but I suppose you can use getpwuid for that.

    Update: this should work

    my $uid = (stat $filename)[4] my $user = (getpwuid $uid)[0]
      That's what I needed.

      Thank you very much.

        use File::stat; use User::pwent;
        Should I Install the User::pwent module for the code to work?
        I am getting the error "The getpwuid function is unimplemented"

        The world is so big for any individual to conquer