Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Stopwatch program

by Crulx (Monk)
on Jan 19, 2000 at 05:27 UTC ( [id://2166]=note: print w/replies, xml ) Need Help??


in reply to Stopwatch program

Time will be your friend here. Something like
use strict; my ($start_time, $end_time, $time_used); my $input; print "Hit enter to start\n"; while (<STDIN> !~ /q/) { $start_time = time; print "Hit enter to stop\n"; $input = <STDIN>; $end_time = time; $time_used = $end_time - $start_time; print "That took $time_used\n"; print "Hit enter to start, q <enter> to quit\n"; }

This uses time so it only has 1 sec granularity. This means that for small time values The error involved in counting could be a large part of the result. To display to the screen, you would have to use non blocking io to get the start and stop enters. Hope this gives you some direction. Crulx

Replies are listed 'Best First'.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-20 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found