CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
I can't figure out how to change my input parameters

 



HarryAchterdeur
Novice

Sep 19, 2012, 12:26 AM

Post #1 of 3 (1110 views)
I can't figure out how to change my input parameters Can't Post

Hello all,

I am really not sure if you can help me, but I thought lets give it a shot.

I've been making a time related typ program to research typing behaviour.

So I have an input function where people can write, and automatically when enter is pressed it goes to the following function.

But I want my script to go to the next function when spacebar is pushed. So in my script, that covers my input section, I want a function like: If 'spacebar' is pressed then go on to the next function. Could you please help me?

use Time::HiRes;
my $start = [ Time::HiRes::gettimeofday( ) ];

Print "Begin typing when you are ready ";
$Tijd = <>;

#here my input comes to life

print "This is what you have typed $Tijd";

my $elapsed = Time::HiRes::tv_interval( $start );
print "Total secondes you needed to create this sentence: $elapsed seconds!\n";

......................................................................................

Now I want the input from $Tijd to go out of $start when spacebar is pushed. So when you make a sentence and you press spacebar the function will be aborted and go to the next one. The goal of this is to brake sentenses into words. So I can see what time is elapsed when certain words are typed.

Hopefully you can help me.

Grtz.

Harry


Laurent_R
Enthusiast / Moderator

Sep 19, 2012, 5:18 AM

Post #2 of 3 (1099 views)
Re: [HarryAchterdeur] I can't figure out how to change my input parameters [In reply to] Can't Post

Hum, two possible ways to try:

- changing the input record separator to space, but I am am not sure that's a good idea in inractive mode.

- read the input char by char and trigger your function when it is a space.


HarryAchterdeur
Novice

Sep 24, 2012, 7:20 AM

Post #3 of 3 (913 views)
Re: [Laurent_R] I can't figure out how to change my input parameters [In reply to] Can't Post

Ty for you reply good sir. I've been trying hard to implement this solution but there is still a fault wich I cannot find:

This is my source code now (i've shortened it)

#! usr/local/bin/perl
use diagnostics;
local $/ = " ";

# aanroepen functie van HiRes (dus de timer);

use Time::HiRes;
my $start = [ Time::HiRes::gettimeofday( ) ];

print "Druk een keer op enter en dan beginnen: \n";
$input = <>;

# Beginnen met de input schermpjes

my $start1 = [ Time::HiRes::gettimeofday( ) ];


$input1 = <>;


my $start2 = [ Time::HiRes::gettimeofday( ) ];


$input2 = <>;


my $start3 = [ Time::HiRes::gettimeofday( ) ];


$input3 = <>;

my $start4 = [ Time::HiRes::gettimeofday( ) ];


$input4 = <>;

my $start5 = [ Time::HiRes::gettimeofday( ) ];


$input5 = <>;

my $start6 = [ Time::HiRes::gettimeofday( ) ];


$input6 = <>;

my $start7 = [ Time::HiRes::gettimeofday( ) ];


$input7 = <>;



#werk van de timer + wat je geschreven hebt

print "$input\n";
my $elapsed1 = Time::HiRes::tv_interval( $start1 );

print "Woord 1: $input1\n";


my $elapsed2 = Time::HiRes::tv_interval( $start2 );

print "Woord 2: $input2\n";


my $elapsed3 = Time::HiRes::tv_interval( $start3 );

print "Woord 3: $input3\n";

my $elapsed4 = Time::HiRes::tv_interval( $start4 );

print "Woord 4: $input4\n";

my $elapsed5 = Time::HiRes::tv_interval( $start5 );

print "Woord 5: $input5\n";

my $elapsed6 = Time::HiRes::tv_interval( $start6 );

print "Woord 6: $input6\n";

my $elapsed7 = Time::HiRes::tv_interval( $start7 );

print "Woord 7: $input7\n";


print "Tijd van woord 1: $elapsed1 seconden!\n";
print "Tijd van woord 2: $elapsed2 seconden!\n";
print "Tijd van woord 3: $elapsed3 seconden!\n";
print "Tijd van woord 4: $elapsed4 seconden!\n";
print "Tijd van woord 5: $elapsed5 seconden!\n";
print "Tijd van woord 6: $elapsed6 seconden!\n";
print "Tijd van woord 7: $elapsed7 seconden!\n";


my $elapsed = Time::HiRes::tv_interval( $start );
print "Totaal van de tekst: $elapsed seconden!\n";

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Output:

Push space and begin:
Hallo
Woord 1: ik
Woord 2: ben
Woord 3: harry
Woord 4: en
Woord 5: ik
Woord 6: snap
Woord 7: hier
Tijd van woord 1: 0.000103 seconden!
Tijd van woord 2: 0.000102 seconden!
Tijd van woord 3: 0.000109 seconden!
Tijd van woord 4: 0.000116 seconden!
Tijd van woord 5: 0.000123 seconden!
Tijd van woord 6: 0.00013 seconden!
Tijd van woord 7: 0.000136 seconden!
Totaal van de tekst: 16.297205 seconden!

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

As you can see the last one is accurate with 16.29 seconds for typing the whole text. But the words alone are not being timed correctly. Thats because the 2nd till the 7th word are not being timed at all. Could you maybe help me with this one?

I myself think that I have to state a clossure to the Timer function everytime a word is prosessed, but I dont know how to do that, not even after excessive searching.

Could you please help again?

Anyway thanks in advance.

*Ps I know that this program can be made wayyy more easier... But I like to do it like this untill I figure out how to do it right...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives