It's a console clock. Uses printf to display the times in hex, binary, decimal, etc.
# hexclock.pl <format>: # Display current time in various formats. # # b zero padded binary integer # c ASCII character # d signed integer # e exponential notation floating point # f decimal notation floting point # o octal integer # p pointer to memory address where time is stored (non-dynamic) # u unsigned integer # x hexadecimal integer (default) use strict; my $fmt = shift ||'x'; $fmt='x' unless ($fmt =~ /[bcdefgopu]/) ; $fmt = "%02$fmt" if ($fmt =~ /[xodu]/) ; $fmt = "%06$fmt" if ($fmt =~ /b/); $fmt = "%0$fmt" if ($fmt !~ /%/); while (1) { my ($h,$m,$s) = split ":",`date +%H:%M:%S:`; printf "\r$fmt : $fmt : $fmt", $h, $m, $s; sleep 1; }

Replies are listed 'Best First'.
Re: hex clock
by inman (Curate) on Apr 14, 2005 at 16:29 UTC
    Why are you using the external date command? One of the time functions (localtime etc.) is probably a better bet.

    If the clock is a hexidecimal clock then surely there should be F hours in a day made up of FF minutes made up of FF seconds. When you started the script you would have to convert the current time into hex time (and account for shorter seconds). You also need to check out the terminal modules so that the time can update in the same place on the console screen.

      I hope you mean that hours would range from 0-F, and minutes and seconds from 00-FF. That makes for about 12 hex seconds per real second, though.
        I wasn't suggesting that 'Hex time' was a good idea per se it's just that representing the passage of time in a different measurement was more interesting than sprintf-ing the plain old hours minutes and seconds.

        What about 16-bit time as a concept? Subdividing a day into FFFF bits isn't too far off the number of conventional seconds in a day.

      Yep, good point, localtime would be better.
      As for coming up with a hex representation of time, maybe I'll try that next...
      Cheers folks
      Charlie