#!/usr/bin/perl -w # countdown.pl: Written by Ed Silva # $Author: ed $ # $Id: countdown.pl,v 1.2 2002/08/20 23:15:54 ed Exp $ # $Date: 2002/08/20 23:15:54 $ # $Name: $ # $Revision: 1.2 $ # $Log: countdown.pl,v $ # Revision 1.2 2002/08/20 23:15:54 ed # changed some comments... # # Revision 1.1.1.1 2002/08/20 23:08:55 ed # Perl Code # # Description: count down to a user specified time. use strict; use Date::Calc qw(Delta_DHMS); use Date::Manip; if (scalar(@ARGV) == 0){ print "when do I count down from?\n"; exit(0); } my $date = join(' ', @ARGV); $date = ParseDate($date); $date = UnixDate($date,"%s"); my @then_tm = localtime($date); for (;;) { my @now_tm = localtime(time()); my ($Dd,$Dh,$Dm,$Ds) = Delta_DHMS($now_tm[5], ($now_tm[4] + 1), $now_tm[3], $now_tm[2], $now_tm[1],$now_tm[0], $then_tm[5], ($then_tm[4] + 1), $then_tm[3], $then_tm[2], $then_tm[1], $then_tm[0]); if (($Dd + $Dh + $Dm + $Ds) <= 0){ last; } clear_screen(); print "T-Minus "; printf("$Dd day%s ", ($Dd == 1) ? "" : "s") if $Dd; printf("$Dh hour%s ", ($Dh == 1) ? "" : "s") if $Dh; printf("$Dm minute%s ", ($Dm == 1) ? "" : "s") if $Dm; printf("$Ds second%s ", ($Ds == 1) ? "" : "s") if $Ds; print "and counting...\n"; print "That's ", ($date - time()), " seconds away...\n"; sleep(1); } print "Woohoo!\n"; exit(0); # vt100 codes to clear the terminal screen... sub clear_screen { printf("\033[2J"); printf("\033[0;0f"); }