For those trying not to go quite so totally geek, a slightly less extreme clock might be something along the lines of:
#!/usr/bin/perl -w
use strict;
$| = 1;
# Set $nice_to_nongeeks true
# to use dual-format display
# for those not yet fluent in binary.
my $nice_to_nongeeks = 1;
while (1) {
my @time_components = localtime(time);
my $datestring = "The current time is: "
. join ( ':',
unpack( "B*", pack( "C", $time_components[2] ) ),
unpack( "B*", pack( "C", $time_components[1] ) ),
unpack( "B*", pack( "C", $time_components[0] ) ) );
if ($nice_to_nongeeks) {
$datestring .= ' ('
. join ( ':',
substr('00' . $time_components[2], -2),
substr('00' . $time_components[1], -2),
substr('00' . $time_components[0], -2) )
. ')';
}
# Append to the string its length in backspace
# characters so as to overwrite its previous output.
# (There may perhaps be some terminals where
# this might not work, however.)
$datestring .= "\b" x length($datestring);
print($datestring);
sleep(1);
}
(I thought the idea of a binary clock was cool, but didn't like represent-each-digit-as-binary approach, thinking the represent-each-component-as-binary was a little more true to the idea.)
Enjoy.
Update: Modified code to force time components in dual-display mode to 2 digits. |