in reply to Re: Shorten this code
in thread Shorten this code
UPDATE: There are a number of golf tricks that I've left out. For instance ("out", "in")[$users{$n} = /\b$n\b/] manages to both remember and select the current state, removing one line. But readability suffers.#!/usr/bin/perl -l -w0777 @users{split /\s+/, <DATA>}=(); while(sleep 2) { $_ = `users`; for my $n (keys %users) { if ($users{$n} xor /\b$n\b/) { $users{$n} = /\b$n\b/; print localtime() . " $n has logged ", $users{$n} ? "in" : "out" +; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Shorten this code
by hostyle (Scribe) on Aug 13, 2004 at 17:44 UTC | |
by BrowserUk (Patriarch) on Aug 13, 2004 at 19:06 UTC |