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

Hi all
I am having some trouble with the following snippet of code. Basically given a user, it's just supposed to return the uid. For whatever the reason, it's returning an ARRAY.. Huh?
$conf{project} = &AskQuestion("What is the base project for this proje +ct", "c", print "***$conf{project}***\n"; my $uid = (getpwnam($conf{project}))[2]; print "***$uid***\n";
Returns..
What is the base project for this project [mail]: ***mail*** Use of uninitialized value in concatenation (.) or string at ./Projcre +ate.pl line 145, <STDIN> line 2. ******
Thanks much
Could someone enlighten me on the finer points of getpwnam. Obviously, I am clueless on this..
Rhodium

The <it>seeker</it> of perl wisdom.

Replies are listed 'Best First'.
Re: Help with getpwnam - and what it returns..
by fokat (Deacon) on Aug 11, 2002 at 04:02 UTC
    To me, this looks a lot as if getpwnam() is failing. You need to be in a system with /etc/passwd or a similar user database (read, a *nix system). Also, you must have a user mail.

    Insure that the following shell command:

    $ id mail
    does return some sensible answer.

    Good luck.

Re: Help with getpwnam - and what it returns..
by Aristotle (Chancellor) on Aug 11, 2002 at 04:05 UTC

    Where did you get the idea it is returning an array?

    Update: for your particular use it should suffice to just my $uin = getpwnam $conf{project} or die "no such user: $conf{project}"; which will probably run into the die() in your case.

    Makeshifts last the longest.

Re: Help with getpwnam - and what it returns..
by kschwab (Vicar) on Aug 11, 2002 at 16:28 UTC
    Maybe just a cut-and-paste typo, but...:

    $conf{project} = &AskQuestion("What is the base project for this project", "c",

    appears to be missing an element, a closing paren, and a semicolon. Perhaps that accounts for the syntax error ?