tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* SUMMARY: getpwuid perl function
@ 1997-07-11 20:56 Ellen Davis
  0 siblings, 0 replies; only message in thread
From: Ellen Davis @ 1997-07-11 20:56 UTC (permalink / raw)
  To: tru64-unix-managers


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1997-07-11 20:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-07-11 20:56 SUMMARY: getpwuid perl function Ellen Davis

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