#!/usr/bin/perl -w use strict; use Time::Duration qw( duration ); # $Id: stopwatch,v 1.2 2003/03/28 07:44:01 adamm Exp $ $| = 1; $SIG{'INT'} = sub { exit(0) }; sub running_time() { my $total = time - $^T; return duration($total); } print "Started at: ", scalar localtime($^T), "\n"; while (1) { my $string = scalar(localtime)." [".running_time()." elapsed.]"; my $spaces = " " x (80 - length($string)); print $string, $spaces; sleep 1; print "\r"; } END { print "\nRan for ", running_time(), "\n"; }