SUMMARY: getpwuid perl function

From: Ellen Davis <daviser_at_email.uc.edu>
Date: Fri, 11 Jul 1997 16:56:14 -0400

The question:

> I'm stumped. Can anyone tell me why this piece of perl code does not set
> any variables except OZlogin?
>
> *************code ********************
> #!/usr/local/bin/perl
>
> ($OZlogin,$pass,$uid,$OZgid,$quota,$comment,$gcos,$OZdir,$shell) =
> getpwuid( $<)
> || die "Who are you?\n";
>
> print "OZlogin=", $OZlogin, " OZdir=", $OZdir , " OZgid=", $OZgid, "\n";
> ************************************************************************


Thanks to:

Juan Gallego
Paul A Sand
Grant Reaber
Kirk Rafferty
Dan West

The answer: There was a precendence problem with the || and the assignment.
In Juan's words:
The problem is that the construct getpwuid || die is evaluated before the
assignment in a scalar context. In the perlfunc man page, it states that
in a in such context the getpw* (and get{gr,host,net,serv}*) just return
the first element. One way to do it is:

(($OZlogin,$pass,$uid,$OZgid,$quota,$comment,$gcos,$OZdir,$shell) =
 getpwuid( $<)) || die "Who are you?\n";

as now the assignment is made first (in an array context) and the
resulting array checked for 'truth'... if it's false, the die statement is
executed...

 Ellen Davis
 Ellen.Davis_at_uc.edu
Received on Fri Jul 11 1997 - 23:07:42 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:36 NZDT