tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: Ellen Davis <daviser () email ! uc ! edu>
To: tru64-unix-managers
Subject: SUMMARY: getpwuid perl function
Date: Fri, 11 Jul 1997 20:56:14 +0000	[thread overview]
Message-ID: <96078614710354.tru64-unix-managers.marc@archive.invalid> (raw)


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@uc.edu

                 reply	other threads:[~1997-07-11 20:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox