home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1275 < prev    next >
Internet Message Format  |  1990-12-28  |  1KB

  1. From: lwall@jato.Jpl.Nasa.Gov (Larry Wall)
  2. Newsgroups: alt.sources,comp.unix.questions,comp.lang.perl
  3. Subject: Re: A Perl version of "wall"
  4. Message-ID: <3594@jato.Jpl.Nasa.Gov>
  5. Date: 6 May 90 03:13:11 GMT
  6.  
  7. In article <KAYVAN.90May5003631@mrspoc.Transact.COM> kayvan@mrspoc.Transact.COM (Kayvan Sylvan) writes:
  8. : In article <264186E0.17B3@tct.uucp> chip@tct.uucp (Chip Salzenberg) writes:
  9. : [... a rather nice version of wall ...]
  10. :     $_ = `who am i 2>/dev/null`;
  11. :     chop;
  12. :     ($me) = split;
  13. :     $me = "Somebody" unless $me;
  14. : Instead of the above, I would do:
  15. :     ($me = getlogin) || (($me) = getpwuid($<)) || ($me = "Somebody");
  16.  
  17. Granted that the manual says something like that, but it can be shortened,
  18. since || always returns one or the other of its arguments, rather than 0 and 1.
  19. [Gee, I suppose I should document that somewhere...]
  20.  
  21. I would say
  22.  
  23.     $me = getlogin || (getpwuid($<))[0] || "Somebody";
  24.  
  25. (Though, of course, that ()[] presumes patchlevel 18.)  You could even say
  26.  
  27.     $me = getlogin || (getpwuid($<))[0] || die "Intruder Alert!\n";
  28.  
  29. Larry
  30.