From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96078614710354.tru64-unix-managers.marc@archive.invalid> From: Ellen Davis Date: Fri, 11 Jul 1997 20:56:14 +0000 To: tru64-unix-managers Subject: SUMMARY: getpwuid perl function X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96078614710354 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