Make the stopwatch note the time every time the "space-button" is pressed.

I am not asking anyone to make this for me, but I would like some info at what I could you best for this. I've made like 30 kinds of different programs for this, but my timer from HiRes is colliding with my input, so it didn't come out just yet.

print " "; #I just let it stay here $input1 = <>; #here I ask for the first word; remember, when I type a sentence it is devided bij the RS by space. (so each input is 1 word).

$elapsed1 = Time::HiRes::tv_interval( $start1 ); #here i redirect the function to the elapsed time

print "Woord 1: $input1\n"; #print the word

print "Tijd van woord 1: $elapsed1 seconden!\n"; #here i print the amount of seconds it took me to type the word

#Now I want to start the second word, and this is exactly where it goes wrong. If you look to the output of the screen you can see that the first #timer function is going on till the input in total stops (so until the last of my functions). The rest of the functions are worthless as you can see. #Only the first timer works, and it does not stop here. $start2 = [ Time::HiRes::gettimeofday( ) ];

Rather than using so many variables ($input1, $input2, $input3, ...$elapsed1, $elapsed2, ..., $start1, $start2)), I think you should at least use a series of arrays. For example, $input[1], $start[1], etc., and loop on the indices.

That would enable you to reduce drastically the code replication (thereby limiting the risk of errors).

In fact a more complex data structure (array of hashes or hash or arrays) would probably be better, but at the very least, use arrays for those three series of variables.

Yes, you are right, from what we can see of the code, the same variables could be simply reused throughout, rather than having to duplicate them as $start1, $start2, etc. I was thinking of arrays in the event that the values need to be used at a later point not shown in the posted code, in which case they would need to be stored.

Thanks for the help with this. @FishMonger the problem is that I want the users to write down an entire text without interruptions. So they have to type a text that is like 300 words. Then I want the program to brake down the words and sentences and put a timestamp on each spacebar that is pushed (so I can calculate what time has passed for that significant word). But with the input function I don't think it is possible, or at least very difficult for me. Maybe it works better if I let the program spin when a user is typing in MSword or something like that. But then again I have no idea how to do that either..

Btw im not programming at school, or learing to program at school. I created my own project and thought I could script this into my project... but I underestimated it.

I will try to use it with the while function... maybe I'll have more questions then to post..