Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

stopwatch

by meonkeys (Chaplain)
on May 06, 2004 at 16:25 UTC ( [id://351198]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info Adam Monsen <adamm@wazamatta.com>
http://adammonsen.com
Description: Simple console-based stopwatch. Assumes 80-character wide terminal. Stop with Control-C. Requires Time::Duration.
#!/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";
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://351198]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found