Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can i specify a pause in a perl/cgi script?

Status
Not open for further replies.

mckarl

Programmer
May 5, 1999
147
GB
hi all, <br><br>here's what i want to do.. i want to simulate a typing motion, <br><br>ie; w-e-l-c-o-m-e---u-s-e-r<br><br>-- now each of the '-' stands for .25 of a second break, do you see what i am trying to say? -- looks like it's being typed in. kinda :)<br><br>i am currently thinking along the lines of:<br><br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=-=-=-=-=-=-<br>#!/usr/bin/perl <br>print &quot;Content-type: text/html&quot;;<br>print &quot;&lt;HTML&gt;\n\t&lt;BODY&gt;\n\n&quot;;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=-=-=-=-=-=-<br><br>-- now i need a way of splitting $username into letters<br>-- anyone know the answer to that too? :))&nbsp;&nbsp;call it $SPLITTINGPROCEDURE<br><br>-- so we got<br><br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=-=-=-=-=-=-<br>#!/usr/bin/perl <br>print &quot;Content-type: text/html&quot;;<br>print &quot;&lt;HTML&gt;\n\t&lt;BODY&gt;\n\n&quot;;<br>@letters = $SPLITTINGPROCEDURE<br>foreach $letter (@letters)<br>{<br>&nbsp;&nbsp;&nbsp;print $letter<br>&nbsp;&nbsp;&nbsp;$WAITFORAPERIOD OF TIME<br>}<br>print &lt;&lt;EndPrint<br><br>to your new thingywhatever, how are you today?<br>&lt;input type=&quot;text&quot; name=&quot;usersanswer&quot; size=&quot;100&quot;&gt;<br>&lt;/BODY&gt;<br>&lt;/HTML&gt;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-=-=-=-=-=-=-<br>so i need a way of splitting up a word into letters, and a way of sectioning out the output by around .25 of a second...&nbsp;&nbsp;<br><br>Thasnks in advance for any help!!<br><br>-- Karl! <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
the 'sleep' function will do that except that it works in whole seconds, not portions of a second.&nbsp;&nbsp;Additionally, I expect you will need to set the print buffer to autoflush, like....<br><br>$¦ = 1;<br><br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Great!!!<br><br><br>-- only, cant i do a <br><br>sleep .25 <br><br>(like in shell script right?)<br><br>-- and what's that flush thing??<br><br><br>-- i have only ever used perl in CGI format. I only started learning CGI a few days ago :)))) <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
You can try it without 'autoflush' on.......I have not tried it, but, I think Perl's default behavior is to buffer its print output.&nbsp;&nbsp;Consequently, you might sleep several times, print to STDOUT and not see any output..... because the print 'content' is still sitting in the buffer.&nbsp;&nbsp;Setting '$¦' to 1, turns <i>autoflush</i> on,&nbsp;&nbsp;effectively setting the print buffer size to zero - everything prints immediately.&nbsp;&nbsp;<br><br>This has some performance costs, so set it back to zero when you no longer need it.<br><br>As I said, I have not tried it, so you may not need to set autoflush on, but, if you don't see your output printing after each 'sleep', autoflush may be the answer. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
If you want to sleep for less than a second you can use the select command, usually used to check if filehandles are ready for reading/writing. However, you can use it to set a pause in milliseconds by:<br><br><FONT FACE=monospace><br>my $timevalue = 250;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#250 milliseconds ie .25 secs<br>my $num_found = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#unused<br>my $time_left = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#unused<br><br>foreach $letter (@letters)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;#pauses for $timevalue seconds<br>&nbsp;&nbsp;&nbsp;&nbsp;($num_found,$time_left) = select(undef, undef, undef, $timevalue);<br>&nbsp;&nbsp;&nbsp;&nbsp;#print next character<br>&nbsp;&nbsp;&nbsp;&nbsp;print &quot;$letter&quot;;<br>}<br></font><br><br>Will this actually simulate the typing though? Even with autoflush on doesn't this mean that your page will take longer to download.. never tried this - neat idea. <br><br>Let us know if it works!<br>Cheers<br><br>Loon<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top