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.


In reply to Re^2: Binary Clock by atcroft
in thread Binary Clock by Legg83

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.