Xref: utzoo alt.sources:1845 comp.unix.questions:21998 comp.lang.perl:1257 Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!zaphod.mps.ohio-state.edu!sdd.hp.com!elroy.jpl.nasa.gov!jato!lwall From: lwall@jato.Jpl.Nasa.Gov (Larry Wall) Newsgroups: alt.sources,comp.unix.questions,comp.lang.perl Subject: Re: A Perl version of "wall" Message-ID: <3594@jato.Jpl.Nasa.Gov> Date: 6 May 90 03:13:11 GMT References: <264186E0.17B3@tct.uucp> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 27 In article kayvan@mrspoc.Transact.COM (Kayvan Sylvan) writes: : In article <264186E0.17B3@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes: : : [... a rather nice version of wall ...] : : $_ = `who am i 2>/dev/null`; : chop; : ($me) = split; : $me = "Somebody" unless $me; : : Instead of the above, I would do: : : ($me = getlogin) || (($me) = getpwuid($<)) || ($me = "Somebody"); Granted that the manual says something like that, but it can be shortened, since || always returns one or the other of its arguments, rather than 0 and 1. [Gee, I suppose I should document that somewhere...] I would say $me = getlogin || (getpwuid($<))[0] || "Somebody"; (Though, of course, that ()[] presumes patchlevel 18.) You could even say $me = getlogin || (getpwuid($<))[0] || die "Intruder Alert!\n"; Larry