A Perl version of "wall"
Larry Wall
lwall at jato.Jpl.Nasa.Gov
Sun May 6 13:13:11 AEST 1990
In article <KAYVAN.90May5003631 at mrspoc.Transact.COM> kayvan at mrspoc.Transact.COM (Kayvan Sylvan) writes:
: In article <264186E0.17B3 at tct.uucp> chip at 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
More information about the Comp.unix.questions
mailing list