Re: Sleep
Hi, I might be being a noob but reading the OP, aren't they wanting to call the value arbitrarily? Meaning, e.g. an Ajax call in a web page could send a request to find out the time remaining in the sleep. I guess that the sleep (which will halt the script) needs to be invoked after forking a decrementing counter? The decrementing counter will run asynchronously and could be queried using Fork::Super bg_eval, but if you are asking this question that might be a stretch (it's not something I've used). As there is 'always more than one way to do it' I would use a fork and a file: The simplest method, if it will do what you want would be to use an until loop to count down and do the sleeping, but you would need to decide up front whether you want to return a value (you could always write it to a file and call the contents of the file?). Need more info on what you want to do with it, but on a basic level, this will work. It passes the sleep time value to countdown and forks that process so the rest of the script can proceed. I put the actual 300 sec sleep at the bottom, but if you cat countdown.txt at any point it will tell you how long is left. #!/usr/bin/perl -w use strict; my $sleep_timer; my $count_amount=('10'); if ( ! fork() ) { countdown($count_amount); } Fork the counting process sub countdown { $sleep_timer = shift; print_remaining($sleep_timer); ##I've put the printing in a routine ## as we need it in two places sleep 1; ### Do the first second sleep before decrementing the counter ### That way it will get all the way down to zero until ($sleep_timer == '0') { $sleep_timer--; print_remaining($sleep_timer);###Pass the current count to our printing sub sleep 1; } } sub print_remaining { my $counter = shift; open FH1 ,+countdown.txt; print FH1 $sleep_timer; close FH1; } ### The main part of the script will hold on until the time has sleep 10; print I waited $count_amount seconds to tell you this; BEWARE using forks that you have some failsafe in place to stop the script being run multiple times, or the same sub will overwrite the counter file so the number will start to jump around all over the place. Hope thats useful. Ed On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote: Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
(DOH - Obviously I was using 10 seconds to test!) On 16 Sep 2013, at 00:49, John W. Krahn jwkr...@shaw.ca wrote: Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
On Sun, Sep 15, 2013 at 6:59 PM, Charles DeRykus dery...@gmail.com wrote: left: , $start+$sleep -time() }; ... Actually, this is wrong because if sleep(3) is interrupted by any signal it will return, so something like this should work, eg my $secs_to_sleep = 60; my $start = time(); my $end = $start + $secs_to_sleep; my $slept; do { local $SIG{USR1} = sub{ say time left: , $end - time()}; my $slept = sleep($secs_to_sleep); $secs_to_sleep -= $slept; } while ( $secs_to_sleep 0 ); -- Charles DeRykus
Sleep
If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks,
Re: Sleep
On Sun, 15 Sep 2013 13:00:36 -0700 Unknown User knowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep
Shawn H Corey wrote: On Sun, 15 Sep 2013 13:00:36 -0700 Unknown Userknowsuperunkn...@gmail.com wrote: If my perl script has a sleep for say 300 seconds, when the sleep is being run is there any way i can find the time remaining in the sleep say by sending a signal? Thanks, Not directly. You have to record the time before the sleep and then you can measure how long the sleep lasted. my $started_sleep = time; sleep 300; my $time_asleep = time - $started_sleep; Or just: my $time_asleep = sleep 300; John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On 2011-06-17 05:34, C.DeRykus wrote: Ruud: C.DeRykus: Ruud: C.DeRykus: Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; Huh? If you insert that statement before doing 'alarm 0', then, there's a potential have a race condition with the alarm going off and terminating the entire program with alarm clock before you can even check $@. Realize that the alarm is then already reset (to the earlier setting) because the localization gets out of scope. No, that's not true. The localized signal handler gets reset but any alarm that is started in that scope will still be delivered to the current signal handler unless turned off. Right, but the word alarm in my sentence stood for alarm signal handler, so please re-read. eval { ... ; foo happens and sets $@='bar'; ... }; my $eval_error = $@ || Zombie error!; # alarm actually does go off now # and terminates program alarm 0; # too late Therefore you wouldn't want to insert any statement before turning off the alarm. Because the alarm signal is localized (to the eval{}), it is not active in the do{}. No, it's still active. In the case below, the alarm that was set inside the scope gets delivered to the default alarm handler. And my alarm signal was short again for alarm signal handler. On freebsd 8.2 for instance: $ perl -e 'eval{ local $SIG{ALRM}=sub{die foo}; alarm 1};' Alarm clock: 14 So the alarm that was launched in the eval {} scope is still active and, even though the localized handler goes out of scope, the delivery still occurs later to the default handler. Well, I hope I cleared up my bad phrasing. Now best read it again. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On Jun 18, 6:50 am, rvtol+use...@isolution.nl (Dr.Ruud) wrote: On 2011-06-17 05:34, C.DeRykus wrote: Ruud: C.DeRykus: Ruud: C.DeRykus: Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; Huh? If you insert that statement before doing 'alarm 0', then, there's a potential have a race condition with the alarm going off and terminating the entire program with alarm clock before you can even check $@. Realize that the alarm is then already reset (to the earlier setting) because the localization gets out of scope. No, that's not true. The localized signal handler gets reset but any alarm that is started in that scope will still be delivered to the current signal handler unless turned off. Right, but the word alarm in my sentence stood for alarm signal handler, so please re-read. I'm sorry to have mis-read your response. With just a signal name, I always tend to interpret it narrowly as the signal itself and not the handler. eval { ... ; foo happens and sets $@='bar'; ... }; my $eval_error = $@ || Zombie error!; # alarm actually does go off now # and terminates program alarm 0; # too late Therefore you wouldn't want to insert any statement before turning off the alarm. Because the alarm signal is localized (to the eval{}), it is not active in the do{}. No, it's still active. In the case below, the alarm that was set inside the scope gets delivered to the default alarm handler. And my alarm signal was short again for alarm signal handler. On freebsd 8.2 for instance: $ perl -e 'eval{ local $SIG{ALRM}=sub{die foo}; alarm 1};' Alarm clock: 14 So the alarm that was launched in the eval {} scope is still active and, even though the localized handler goes out of scope, the delivery still occurs later to the default handler. Well, I hope I cleared up my bad phrasing. Should have been clear to me in that context what you were referring to. Turning off the undelivered alarm is good practice but I'll re-read the whole thread. -- Charles DeRykus . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On 2011-06-15 14:18, C.DeRykus wrote: [...] mixing alarm/sleep is a bad idea. See: perldoc -f alarm. Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; and use $eval_error in the code below. alarm 0; if ( $@ =~ /alarm/) { warn expired... } } elsif ( $@ =~ /usr1/) { redo EVAL; } } elsif ($@){ die unexpected error: $@; } } } Realize that $@ is a global variable, so can get changed at a distance. The last 'elsif' was particularly wrong: it would not die if $@ is false. Just make it an 'else'. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On Jun 16, 1:54 am, rvtol+use...@isolution.nl (Dr.Ruud) wrote: On 2011-06-15 14:18, C.DeRykus wrote: [...] mixing alarm/sleep is a bad idea. See: perldoc -f alarm. Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; Huh? If you insert that statement before doing 'alarm 0', then, there's a potential have a race condition with the alarm going off and terminating the entire program with alarm clock before you can even check $@. eval { ... ; foo happens and sets $@='bar'; ... }; my $eval_error = $@ || Zombie error!; # alarm actually does go off now # and terminates program alarm 0; # too late Therefore you wouldn't want to insert any statement before turning off the alarm. Particularly if the alarm handler is localized to the eval{} which is the best idion. and use $eval_error in the code below. alarm 0; if ( $@ =~ /alarm/) { warn expired... } } elsif ( $@ =~ /usr1/) { redo EVAL; } } elsif ($@) { die unexpected error: $@; } } } Realize that $@ is a global variable, so can get changed at a distance. Yes, but $@ was just set and the immediate danger is an alarm race condition that needs to be addressed first. The eval {} was just exited after all and nothing intervenes except the $@ condition if-elsif clauses that needed to protected from an uncaught alarm. The last 'elsif' was particularly wrong: it would not die if $@ is false. Just make it an 'else'. But what kind of scenario would do that? If there's an uncaught signal for instance, the program will still terminate immediately with an alarm clock. Or if the program unexpectedly exits in some benign way inside the eval {}, you'd never see that final 'else' clause anyway. If the final statement '1' in the eval {} gets short-circuited somehow, I'd think all bets are off. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On 2011-06-16 19:16, C.DeRykus wrote: Ruud: C.DeRykus: Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; Huh? If you insert that statement before doing 'alarm 0', then, there's a potential have a race condition with the alarm going off and terminating the entire program with alarm clock before you can even check $@. Realize that the alarm is then already reset (to the earlier setting) because the localization gets out of scope. eval { ... ; foo happens and sets $@='bar'; ... }; my $eval_error = $@ || Zombie error!; # alarm actually does go off now # and terminates program alarm 0; # too late Therefore you wouldn't want to insert any statement before turning off the alarm. Because the alarm signal is localized (to the eval{}), it is not active in the do{}. To support 'nested' alarms (actually more 'in turns' than 'nested'), you might want to do it like this: EVAL: { my $prev_timeout = alarm 0; # stop any outer alarm my $timeout = 20; eval { my $alarm_on = 1; local $SIG{ ALRM } = sub { die evalarm if $alarm_on }; local $SIG{ USR1 } = sub { $alarm_on = 0; die usr1 }; alarm $timeout; ... some long running operation here (that might die itself) ... $alarm_on = 0; alarm $prev_timeout; # re-activate any outer alarm 1; # success } or do { my $eval_error = $@ || Zombie error!; alarm $prev_timeout; # re-activate any outer alarm if( $eval_error =~ /evalarm/ ) { warn expired... } elsif ( $eval_error =~ /usr1/) { redo EVAL } else { die $eval_error } }; } -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On Jun 16, 3:00 pm, rvtol+use...@isolution.nl (Dr.Ruud) wrote: On 2011-06-16 19:16, C.DeRykus wrote: Ruud: C.DeRykus: Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { Insert: my $eval_error = $@ || Zombie error!; Huh? If you insert that statement before doing 'alarm 0', then, there's a potential have a race condition with the alarm going off and terminating the entire program with alarm clock before you can even check $@. Realize that the alarm is then already reset (to the earlier setting) because the localization gets out of scope. No, that's not true. The localized signal handler gets reset but any alarm that is started in that scope will still be delivered to the current signal handler unless turned off. eval { ... ; foo happens and sets $@='bar'; ... }; my $eval_error = $@ || Zombie error!; # alarm actually does go off now # and terminates program alarm 0; # too late Therefore you wouldn't want to insert any statement before turning off the alarm. Because the alarm signal is localized (to the eval{}), it is not active in the do{}. No, it's still active. In the case below, the alarm that was set inside the scope gets delivered to the default alarm handler. On freebsd 8.2 for instance: $ perl -e 'eval{ local $SIG{ALRM}=sub{die foo}; alarm 1}; ' Alarm clock: 14 So the alarm that was launched in the eval {} scope is still active and, even though the localized handler goes out of scope, the delivery still occurs later to the default handler. ... -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
On Jun 14, 3:31 am, gator...@yahoo.de wrote: Hi, On 2011-06-14 09:23, gator...@yahoo.de wrote: what I am trying to do is: - run a little program, that just sleeps for a given time - when it receives a signal, restarts sleeping again for the full time period until it receives another signal or the timer elapses. In the latter case it should just exit. Something like: sub sleeper { warn strftime(%H:%M:%S sleep $sleeptime\n, localtime); $SIG{USR1}=\sleeper; sleep $sleeptime; }; warn $$; sleeper; It sounds very simple, but I can't get it to work as intended. ... meanwhile a found a solution; in case somebody with the same problem stumbles upon this, here's what I came up with: my $caught_signal=0; sub expired { warn strftime(%H:%M:%S expired\n, localtime); exit 0; } sub sleeper { warn strftime(%H:%M:%S sleep $sleeptime\n, localtime); alarm $sleeptime; pause; }; sub usr1 { alarm 0; $caught_signal=1; } $SIG{USR1}=\usr1; $SIG{ALRM}=\expired; while(1) { if($caught_signal) { $caught_signal=0; } else { sleeper(); } } The problem obviously was, that I called sleep from within the USR1 signal handler and (generally not a bad idea ;) this signal had been blocked there. If somebody knows a more elegant solution, let me know ... Not sure of your actual program detail but mixing alarm/sleep is a bad idea. See: perldoc -f alarm. Another solution, not necessarily more elegant, but more familiar to most is an eval {} and alarm pair: EVAL: { eval { local $SIG{ ALRM } = sub { die alarm; }; local $SIG{ USR1 } = sub { die usr1 }; alarm $sleeptime; ... some long running operation here alarm 0; 1; } or do { alarm 0; if ( $@ =~ /alarm/) { warn expired... } } elsif ( $@ =~ /usr1/) { redo EVAL; } } elsif ($@){ die unexpected error: $@; } } } -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Reliably restarting sleep
Hi, the subject is admittedly not very enlighening ... ;-; what I am trying to do is: - run a little program, that just sleeps for a given time - when it receives a signal, restarts sleeping again for the full time period until it receives another signal or the timer elapses. In the latter case it should just exit. Something like: sub sleeper { warn strftime(%H:%M:%S sleep $sleeptime\n, localtime); $SIG{USR1}=\sleeper; sleep $sleeptime; }; warn $$; sleeper; It sounds very simple, but I can't get it to work as intended. I tryied it in numberless variations using sleep, Time::HiRes, alaram/pause ... the actual result is always pretty much the same: - When the program receives the 1st USR1 signal, it is interrupted immediately and sleeper is called. The pending alarm is obviously canceled and restarted as intended - Any subsequent USR1 signal is only reacted to when the full $sleeptime starting from the previous signal is elapsed. If more than 1 signal is received in the meantime, additional signals are lost. Does anybody have an idea why this doesn't work and how to get the intendeded result? Any suggestions are appreciated ... (This is taking place on a Linux 2.6.32 kernel using perl 5.10.0 ...) Regards, Peter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Reliably restarting sleep
Hi, On 2011-06-14 09:23, gator...@yahoo.de wrote: what I am trying to do is: - run a little program, that just sleeps for a given time - when it receives a signal, restarts sleeping again for the full time period until it receives another signal or the timer elapses. In the latter case it should just exit. Something like: sub sleeper { warn strftime(%H:%M:%S sleep $sleeptime\n, localtime); $SIG{USR1}=\sleeper; sleep $sleeptime; }; warn $$; sleeper; It sounds very simple, but I can't get it to work as intended. ... meanwhile a found a solution; in case somebody with the same problem stumbles upon this, here's what I came up with: my $caught_signal=0; sub expired { warn strftime(%H:%M:%S expired\n, localtime); exit 0; } sub sleeper { warn strftime(%H:%M:%S sleep $sleeptime\n, localtime); alarm $sleeptime; pause; }; sub usr1 { alarm 0; $caught_signal=1; } $SIG{USR1}=\usr1; $SIG{ALRM}=\expired; while(1) { if($caught_signal) { $caught_signal=0; } else { sleeper(); } } The problem obviously was, that I called sleep from within the USR1 signal handler and (generally not a bad idea ;) this signal had been blocked there. If somebody knows a more elegant solution, let me know ... Regards, Peter -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
sleep exactly after n seconds (sleep finishing longer than specified)
Hi, I have a script that forks a child. at the parent, i have a line that tells it to sleep for n seconds. Once the 3 seconds have passed, it will kill the child process. I noticed that most of the time, sleep doesn't count exact seconds.. most of the time it's longer. Is there any way to sleep precisely for n seconds? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sleep exactly after n seconds (sleep finishing longer than specified)
On Wed, Apr 22, 2009 at 09:27, Michael Alipio daem0n...@yahoo.com wrote: Hi, I have a script that forks a child. at the parent, i have a line that tells it to sleep for n seconds. Once the 3 seconds have passed, it will kill the child process. I noticed that most of the time, sleep doesn't count exact seconds.. most of the time it's longer. Is there any way to sleep precisely for n seconds? snip Not unless you are using a realtime OS. Your process might not get CPU time for n+m seconds. Until your process gets CPU time it doesn't matter what you put in sleep, nothing will happen. You may be able to schedule a process such that it will always have CPU time, but performance will suffer for everything else (which is why realtime OSes suck for everything but medical, weapon systems, and other tasks that must have sub-microsecond timing). You must trade speed for precision. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sleep exactly after n seconds (sleep finishing longer than specified)
Michael Alipio wrote: Hi, Hello, I have a script that forks a child. at the parent, i have a line that tells it to sleep for n seconds. Once the 3 seconds have passed, it will kill the child process. I noticed that most of the time, sleep doesn't count exact seconds.. most of the time it's longer. Is there any way to sleep precisely for n seconds? Not really, but you can get finer grained timing using select() perldoc -f select Or the Time::HiRes module. perldoc Time::HiRes John -- Those people who think they know everything are a great annoyance to those of us who do.-- Isaac Asimov -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Sleep
Hi, How could I introduce a Sleep in Perl? Is there any specific function for that? regards, -ramesh P Save a tree...please don't print this e-mail unless you really need to Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com
RE: Sleep
Hi, How could I introduce a Sleep in Perl? Is there any specific function for that? regards, -ramesh Yes. It's called sleep sleep n - will sleep for n seconds (miss off the number and it'll sleep until interrupted) Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini UK plc, a company registered in England and Wales (number 943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: Sleep
Thank You. -Original Message- From: Taylor, Andrew (ASPIRE) [mailto:andrew.tayl...@hmrcaspire.com] Sent: Wednesday, March 04, 2009 3:51 PM To: beginners@perl.org Subject: RE: Sleep Hi, How could I introduce a Sleep in Perl? Is there any specific function for that? regards, -ramesh Yes. It's called sleep sleep n - will sleep for n seconds (miss off the number and it'll sleep until interrupted) Capgemini is a trading name used by the Capgemini Group of companies which includes Capgemini UK plc, a company registered in England and Wales (number 943935) whose registered office is at No. 1 Forge End, Woking, Surrey, GU21 6DB. This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Sleep apnea
On Oct 16, 2:09 pm, [EMAIL PROTECTED] (Jenda Krynicky) wrote: use FileHandle; The FileHandle module exists largely for reasons of backward compatibility. New code should: use IO::Handle; or use IO::File; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Sleep apnea
I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Sleep apnea
Try setting buffering off, its probably due to that as it should do a,b,c -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: 16 October 2007 02:50 To: beginners@perl.org Subject: Sleep apnea I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
On 10/15/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. snip You didn't find anything in perldoc -f sleep because the problem is not with sleep. The pause is there, but STDOUT is buffered by default so you will not see the result of the first print until the buffer is full, you print a \n, or the program exits. Try this instead: use strict; use warnings; print 8*8, \n; sleep 3; print 7*7, \n; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
On Oct 16, 6:11 am, [EMAIL PROTECTED] (Chas. Owens) wrote: On 10/15/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? BTW, I did perldoc -f sleep. If it explains this behavior, I didn't understand it. snip You didn't find anything in perldoc -f sleep because the problem is not with sleep. The pause is there, but STDOUT is buffered by default so you will not see the result of the first print until the buffer is full, you print a \n, or the program exits. Try this instead: use strict; use warnings; print 8*8, \n; sleep 3; print 7*7, \n; Rather than changing the output by adding newlines, you can simply turn output buffering off: $|++; Read about the $| variable in `perldoc perlvar` Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Sleep apnea
From: [EMAIL PROTECTED] I would expect the following script: use strict; use warnings; print 8*8; sleep 3; print 7*7; To behave as follows. 1. print 64. 2. pause 3 seconds. 3. print 49. Instead the behavior is: 1. pause 3 seconds. 2. print 64. 3. print 49. Why is that, and how do I insert a pause in between these two print commands (as an example)? Standard output is line-buffered by default. Try: use strict; use warnings; use FileHandle; STDOUT-autoflush(); print 8*8; sleep 3; print 7*7; HTH, Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
how to sleep 100 miliseconds?
hi. I'm new at perl and am looking for solution of let script sleep for few miliseconds. I tried sleep(0.1); but it does not work :) as I thought. than I found this solution: select undef, undef, undef, .01; but it freezes script and it does not continue. Thanks for any ideas. TOKO -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how to sleep 100 miliseconds?
TOKO wrote: hi. I'm new at perl and am looking for solution of let script sleep for few miliseconds. I tried sleep(0.1); but it does not work :) as I thought. Easist way IMO is to use Time::HiRes: use Time::HiRes qw(sleep); sleep(0.1); than I found this solution: select undef, undef, undef, .01; but it freezes script and it does not continue. Strange, that should work. What platform are you on? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: how to sleep 100 miliseconds?
TOKO wrote: hi. I'm new at perl and am looking for solution of let script sleep for few miliseconds. I tried sleep(0.1); but it does not work :) as I thought. than I found this solution: select undef, undef, undef, .01; but it freezes script and it does not continue. Thanks for any ideas. TOKO You could use Time::HiRes which is also mentioned in perldoc -f sleep. Sleep only works with a granularity of one second. http://search.cpan.org/~jhi/Time-HiRes-1.83/HiRes.pm hth E. -- Elie De Brauwer -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: how to sleep 100 miliseconds?
TOKO [EMAIL PROTECTED] asked: hi. I'm new at perl and am looking for solution of let script sleep for few miliseconds. I tried sleep(0.1); but it does not work :) as I thought. than I found this solution: select undef, undef, undef, .01; but it freezes script and it does not continue. Use usleep() from the Time::Hires module: http://search.cpan.org/dist/Time-HiRes/ HTH, Thomas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
about sleep: is it a bug?
HI, I found a problem in my script.I call sleep function in a child process (sleep 3600 sec,then wake up and do something). But these days I found sleep can't wake up.I checked it carefully,and find that when sleeping,if disks I/O error occured (such as 100% disks space using,no free space for writing),the sleep will have something the matter -- it never wake up from that time. Is this true?and how can I resolve this problem?tks more. btw: my codes about sleep are below: die can't fork:$! unless defined (my $child = fork()); if ($child==0) { while(1) { sleep 3600; my %total=(); open (HD,$log) or die can't read from logfile:$!; while(HD) { next if /^$/; chomp; my ($mbox_id,$size,$type)=split(/:/,$_); $total{$mbox_id}{$type}+=$size; } close HD; `cat /dev/null $log`; disable(\%total); } } -- -- Jeff Pan [EMAIL PROTECTED] -- http://www.fastmail.fm - Choose from over 50 domains or use your own -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Most efficent way to sleep until ...
Hello. I am writing a perl program that sleeps until I get a notification from through Postgres DBD then wakes up and does something. Here is how it works now: my $sleeptime = 0.10; $dbh-do(LISTEN mysignal); while () { $listen = $dbh-func('pg_notifies'); if (ref($listen)) { do_some_sub_here(); } select(undef, undef, undef, $sleeptime); } Is there a more efficient way to do this? Right now my program is waking up and evaluating if $listen is defined each time it wakes up. This does work quite well, when I look in top I see the program uses 0% CPU while sleeping. I would like to make my program as responsive as possible so I was wondering if there was some way to make this more efficient? Like some way to tell perl to sleep indefiantely unless $listen becomes defined. Thank you. Johnny _ MSN® Calendar keeps you organized and takes the effort out of scheduling get-togethers. http://join.msn.com/?pgmarket=en-capage=byoa/premxAPID=1994DI=1034SU=http://hotmail.com/encaHL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
while(1){print a; sleep 1;}
Hi All, Why I dont get a's printed with the code below? +++ while(1) { print a; sleep 1; } +++ It works well if I print a newline with a, i.e while(1) { print a\n; # newline with a sleep 1; } Please help if you know the cause. TIA Tapas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: while(1){print a; sleep 1;}
TapasranjanMohapatra [T], on Wednesday, February 9, 2005 at 19:47 (+0530) typed the following: T It works well if I print a newline with a, i.e I hope it works without sleep 1, try that, and you will see the answer. -- ...m8s, cu l8r, Brano. [You should never go in there without a mongoose. - 007 (L. L. D.)] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: while(1){print a; sleep 1;}
On Wed, 9 Feb 2005, TapasranjanMohapatra wrote: Why I dont get a's printed with the code below? Apparently it's an output buffering issue. If you flush output, it works: $ perl -e 'while(1){printa;sleep 1}' ^C $ perl -e '$|=1;while(1){printa;sleep 1}' aaa^C $ So, setting $| to 1 seems to fix the problem... -- Chris Devers -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
RE: while(1){print a; sleep 1;} -my thanks
-Original Message- From: Chris Devers [mailto:[EMAIL PROTECTED] Sent: Wed 2/9/2005 8:01 PM To: TapasranjanMohapatra Cc: Perl Beginners List Subject:Re: while(1){print a; sleep 1;} On Wed, 9 Feb 2005, TapasranjanMohapatra wrote: Why I dont get a's printed with the code below? Apparently it's an output buffering issue. If you flush output, it works: $ perl -e 'while(1){printa;sleep 1}' ^C $ perl -e '$|=1;while(1){printa;sleep 1}' aaa^C $ So, setting $| to 1 seems to fix the problem... -- Chris Devers Thanks Chris, Forcing the flush after print solves the problem. Tapas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: while(1){print a; sleep 1;}
TapasranjanMohapatra ha scritto: Hi All, Why I dont get a's printed with the code below? +++ while(1) { print a; sleep 1; } +++ It works well if I print a newline with a, i.e while(1) { print a\n; # newline with a sleep 1; } Please help if you know the cause. TIA Tapas I think the problem is output buffering. The buffer doesn't get flushed (i.e. its content printed to screen) until it's full. I guess the newline character causes the buffer to be flushed. To force buffer flushing after each print, you can se $| to a non-zero value. I attached a sample script to show this. Marcello use strict; use warnings; $|++; while(1) { print a; # with this line we don't get any output unless we put a $|++ beforehand #print a\n; # with this line every a gets printed regardless of $| value (0 or 1) sleep 1; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: while(1){print a; sleep 1;}
- Original Message - From: TapasranjanMohapatra [EMAIL PROTECTED] Date: Wednesday, February 9, 2005 9:17 am Subject: while(1){print a; sleep 1;} Hi All, Hello, Why I dont get a's printed with the code below? Works well on my system, are you sure you are not redirecting the output somewhere ?? +++ while(1) { print a; sleep 1; } +++ It works well if I print a newline with a, i.e while(1) { print a\n; # newline with a sleep 1; } Please help if you know the cause. TIA Tapas -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
using Sleep instead of Cron
Hi all, I'm writing a script which fetches data every hour. I thought instead of using cron which is platform dependent, to use sleep and a goto statement. Is there any downfalls to this? At the start of the script I check to see if it was ran in the previous hour. BEGINNING: if(open(TIMECHECK, ./synop_daemon_timer.txt)){ my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK; my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); if($cur_hour1 eq $cur_hour $cur_day1 eq $cur_day){ print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE; exit(0); } close(TIMECHECK); } # at the end of the script I write the last time the script was started if(open(TIMER, ./synop_daemon_timer.txt)){ my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n; close(TIMER); } sleep(360); goto(BEGINNING); Thanks
Re: using Sleep instead of Cron
On Tue, 2004-05-18 at 16:02, [EMAIL PROTECTED] wrote: Hi all, I'm writing a script which fetches data every hour. I thought instead of using cron which is platform dependent, to use sleep and a goto statement. Is there any downfalls to this? Yes. With sleep, once the machine is restarted, your process goes away. With Cron, everything resumes its normal behaviour (and there are probably other downfalls). At the start of the script I check to see if it was ran in the previous hour. BEGINNING: if(open(TIMECHECK, ./synop_daemon_timer.txt)){ my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK; my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); if($cur_hour1 eq $cur_hour $cur_day1 eq $cur_day){ print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE; exit(0); } close(TIMECHECK); } I think this is too much work for something that Cron already does... are you really going to take your code to a platform without Cron? # at the end of the script I write the last time the script was started if(open(TIMER, ./synop_daemon_timer.txt)){ my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n; close(TIMER); } sleep(360); goto(BEGINNING); Thanks Take a look at Schedule::Cron HTH, jac -- Jos Alves de Castro [EMAIL PROTECTED] Telbit - Tecnologias de Informao -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using Sleep instead of Cron
On Tue, 2004-05-18 at 16:02, [EMAIL PROTECTED] wrote: Hi all, I'm writing a script which fetches data every hour. I thought instead of using cron which is platform dependent, to use sleep and a goto statement. Is there any downfalls to this? Other downfalls: - Cron has automatic e-mail sending (should things go awry) - With Cron, you know it runs every *exact* hour (OTOH, a script started at 15:15 would keep running at *:15 plus some incrementing delay) - service crond start / stop / status are a very good way of keeping track of cron processes. Should you want to stop your script, you would have to find its process id and kill it; plus, running it again would make it run some time later/sooner than expected at first (again, cron resumes normal behaviour). - others, certainly At the start of the script I check to see if it was ran in the previous hour. BEGINNING: if(open(TIMECHECK, ./synop_daemon_timer.txt)){ my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK; my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); if($cur_hour1 eq $cur_hour $cur_day1 eq $cur_day){ print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE; exit(0); } close(TIMECHECK); } # at the end of the script I write the last time the script was started if(open(TIMER, ./synop_daemon_timer.txt)){ my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n; close(TIMER); } sleep(360); goto(BEGINNING); Thanks -- Jos Alves de Castro [EMAIL PROTECTED] Telbit - Tecnologias de Informao -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using Sleep instead of Cron
Hi all, I'm writing a script which fetches data every hour. I thought instead of using cron which is platform dependent, to use sleep and a goto statement. Is there any downfalls to this? Sure, all of the differences between a one-off script and a constantly running program. cron is platform dependent, but just about every platform (at least where Perl runs) has a scheduler of some sort, and cron is available on most of them. I am not saying not to do it, just make sure you do it for the right reasons and get the mileage you expect. At the start of the script I check to see if it was ran in the previous hour. BEGINNING: if(open(TIMECHECK, ./synop_daemon_timer.txt)){ my($cur_sec1,$cur_min1,$cur_hour1,$cur_day1,$cur_mon1) = TIMECHECK; my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year)=gmtime(time()); if($cur_hour1 eq $cur_hour $cur_day1 eq $cur_day){ print br SCRIPT IS ALREADY IN ACTION, CANNOT CONTINUE; Already in action? You mean has already run. Big difference, at least when you are talking about making a jump like this. What happens during daylight savings time, assuming your platform has such a thing? What happens if the system time changes, do you run ntpd? exit(0); } close(TIMECHECK); } # at the end of the script I write the last time the script was started if(open(TIMER, ./synop_daemon_timer.txt)){ 'started' or 'ran'... big difference again. my($cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon,$cur_year,$junk)=gmtime(time()); print TIMER $cur_sec,$cur_min,$cur_hour,$cur_day,$cur_mon\n; close(TIMER); } sleep(360); This sleeps for 6 minutes from whenever the last iteration finished, this is a very different thing then when running with a scheduler which is going to run at specific times. aka if you start your script at 12:02 then it runs at 12:08, etc. However, if your script starts at 12:03, then it runs at 12:09, etc. A scheduler will make sure it runs consistently, because it doesn't depend on when it was started (aka because it isn't constantly running). Add to this the dependency on the run time, aka if the processing itself takes a while or is dependent on external uncontrollable forces, such as network speed. Maybe your script starts at 12:04, the first loop takes 2 minutes to run, then your script will run again at 12:12, but this time takes 4 minutes to run, so the next run starts at 12:22, so much for consistency :-) goto(BEGINNING); Speaking of constantly running, are you going to monitor that the process is still alive. How about adding it to the init functions of the computer, in other words, cron is started at boot time, and just runs your script at the next interval. A constantly running program would need to be added to the platform's boot sequence. Can anyone reboot the machine, aka are the sys admin's aware of your app? You may also want to check out Proc::Daemon, are you going to redirect STDIN/STDERR/STDOUT to a log? How about disassociating the process from the terminal? Also consider an 'alarm' call, though I am not sure whether it is considered better or worse than a 'sleep'. perldoc -f alarm Lots to think about, I would caution you to at least think about all of the things that could go wrong with this approach. But again, I am not telling you not to do it http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: using Sleep instead of Cron
My main concern was that the script would die from SIGALARM. I'm testing on and XP box and using the script on a FreeBSD box. How can I get the cron function on my XP box? Also I have to get admin permission for cron jobs. Which I don't think will be a problem. It's not important that the script be ran in exact time intervals. But it is important that I be able to kill the process if necessary, and that it not quit functioning in the middle of the night. So I guess cron is the best way. Thanks so much Tricia
sleep under windows cmd
Hi helpers, I'm very new in perl programming(in programming at all acutally) and wondering about the following piece of code which I was running under W2K command-line: print First; sleep 2; print Second; I thought the script would print First then wait for 2 seconds and than print Second. But the script ist waiting 2 seconds first and than it print FirstSecond Thanks for your help. d a n i e l -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sleep under windows cmd
$| = 1; #Autoflush print First; sleep 2; print Second; -Will --- Handy Yet Cryptic Code. Just to Look Cool to Look at and try to decipher without running it. Windows perl -e printf qq.%3i\x20\x3d\x20\x27%c\x27\x09.,$_,$_ for 0x20..0x7e Unix perl -e 'printf qq.%3i\x20\x3d\x20\x27%c\x27%7c.,$_,$_,0x20 for 0x20..0x7e'
Re: sleep under windows cmd
On 02/22/04 05:09, daniel wrote: Hi helpers, I'm very new in perl programming(in programming at all acutally) and wondering about the following piece of code which I was running under W2K command-line: print First; sleep 2; print Second; I thought the script would print First then wait for 2 seconds and than print Second. But the script ist waiting 2 seconds first and than it print FirstSecond By default, output to the console is buffered for efficiency. Since output to the console is relatively expensive in terms of time the system libraries will save up a couple of output operations and ouput it at once. Most of the time this is what you want, but occasionally it gets in the way. The perl idiom for turning of the output buffering to the console is: $| = 1; (You can look up the special variable $| in the perlvar manpage.) Put the above line at the top of your script and output will be unbuffered, i.e. it will appear as soon as the print function is completed. Regards, Randy. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: sleep does not work when SIGIO is handled (O_ASYNC). why?
On Dec 28, 2003, at 2:57 AM, Artem Koutchine wrote: [..] In order not to waste CPU time and have server do something usufull (like calculating something) i tried handling SIGIO, so, when data is available on incoming connection i handle and when there is no data, server does its own job. However, it figures, that when i added fcntl(STDIN, F_SETFL, O_ASYNC|O_NONBLOCK); sleep(5) stopped working right. It does not wait for 5 seconds any longer, but actually for about 1/3 second and fully ignores the sleep time a specify (you can run the server and connect to it using telnet and see for yourself). I could not find any info on sleep (SIGALRM) messing with SIGIO and O_ASYNC mode. Any ideas what's going on and how to fix this? [..] this sounds like one of the 'bugs' in perl 5.8.0 and/or 5.8.1 that is suppose to be fixed in 5.8.2 - One strategy would be to create a SIGALRM handler that would set a flag value you could check to see if your alarm went off and was handled. ciao drieux --- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
sleep does not work when SIGIO is handled (O_ASYNC). why?
Hi! Below - the actual server code. Here is the explanation and the problem. I am writing a TCP multiplexing server which, when user connects, forks and the sends ever 5 seconds a message to the client and also listen to what client send to server and does something. In order not to waste CPU time and have server do something usufull (like calculating something) i tried handling SIGIO, so, when data is available on incoming connection i handle and when there is no data, server does its own job. However, it figures, that when i added fcntl(STDIN, F_SETFL, O_ASYNC|O_NONBLOCK); sleep(5) stopped working right. It does not wait for 5 seconds any longer, but actually for about 1/3 second and fully ignores the sleep time a specify (you can run the server and connect to it using telnet and see for yourself). I could not find any info on sleep (SIGALRM) messing with SIGIO and O_ASYNC mode. Any ideas what's going on and how to fix this? Best regards, Artem # CODE!! #!/usr/bin/perl use strict; use POSIX; use Socket; use Fcntl; sub spawn; my $server_port=9871; my $server_protocol=getprotobyname('tcp'); socket(Server, PF_INET, SOCK_STREAM, $server_protocol) || die Socket: $!\n; setsockopt(Server, SOL_SOCKET, SO_REUSEADDR, pack(l,1)) || die setsockopt: $!\n; bind(Server, sockaddr_in($server_port,INADDR_ANY)) || die Bind: $!\n; listen(Server, SOMAXCONN) || die Listed: $!\n; warn Server started on port $server_port!\n; my $waitedpid = 0; my $paddr; sub REAPER { $waitedpid=wait; $SIG{CHLD}=\REAPER; warn reaped $waitedpid . ($? ? with exit $? : '').\n; } my $buf; sub INCOMING { # see if anythinhg is waiting in the IN queue my ($rin,$win,$ein); $rin=$win=$ein=''; vec($rin,fileno(STDIN),1)=1; $ein=$rin|$win; my ($aa,$bb)=select($rin,$win,$ein,0); if ($aa){ warn Incoming data!\n; # accumulate; $buf=$buf.STDIN; warn $buf.\n; } } $SIG{CHLD}=\REAPER; for ($waitedpid=0;($paddr=accept(Client,Server)) || $waitedpid; $waitedpid=0, close Client){ next if $waitedpid and not $paddr; my ($port, $iaddr) = sockaddr_in($paddr); warn Connection from ip:.inet_ntoa($iaddr). port: .$port.\n; spawn sub { $|=1; $buf=''; my $k=0; # install read handler warn CHILD: Installing signal handlers\n; $SIG{'IO'}=\INCOMING; warn CHILD: Turning on async mode on STDIN\n; fcntl(STDIN, F_SETFL, O_ASYNC|O_NONBLOCK); fcntl(STDIN, F_SETOWN, $$); warn CHILD: looping...\n; my $msg; while(1){ $msg=Hello client! I am sever! - $k\n; print $msg; #send (Client,$msg,length($msg)); sleep(5); $k++; } } } sub spawn { my $coderef=shift; my $pid; if (!defined($pid=fork)){ return; } elsif ($pid) { warn I am parent - $pid.\n; return; } # child here select(Client); $|=1; open (STDIN, Client) || die cannot dup client to stdin\n; open (STDOUT, Client) || die cannot dup client to stdout\n; #open (STDERR, Client) || die cannot dup cleint to stderr\n; select(STDOUT); $|=1; exit $coderef(); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ http://learn.perl.org/first-response
Re: Flock and Sleep
On Fri, 8 Aug 2003 02:32:05 +0500, Sara wrote: open(NUMBER,data.txt); flock (NUMBER, 2); close (NUMBER); closing a file automatically removes the lock?? The answer is yes. When you close files they will automatically un-locked. One thing though, you might want to use the fcntl module which imports the following flock constants: # Importing flock constants: # (LOCK_SH, LOCK_EX, LOCK_NB and LOCK_UN) use fcntl ':flock'; My second question is how I can delay the execution of a script (If two users trying to execute the same script) for 30 sec by using sleep function? and If I implement sleep function in my script . Do I really need to use 'flock' in my script or there is no need then. It depends in which environment you want to run your script. If it only needs to run in the *nix world you might want your script to: (a) check for a file (-e) (b) if file doesn't exist, create it and write the scripts PID (getpid() or $$ or $PID or $PROCESS_ID) into it (c) if the file is found read the PID and ping the PID for existance (sending a signal with kill()) [*] (d) if PID exists you will wait 30 seconds (sleep()) and go back to (c) or wait for the other script to finish (waitpid()). (e) once your script gets the ok from (a) or (d) you can goto (b). If you are interested in another solution which will die () if the same script is already running, just ping me by email. thanks /oliver [*] You might want to install a signal handler in your script that will ignore the send signal though. E.g.: local $SIG{INT} = 'IGNORE'; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Flock and Sleep
(sub get_number { open(NUMBER,data.txt); flock (NUMBER, 2); Do blah blah blah close (NUMBER); closing a file automatically removes the lock?? or should I have to unlock it by placing flock (NUMBER, 8); close (NUMBER); My second question is how I can delay the execution of a script (If two users trying to execute the same script) for 30 sec by using sleep function? and If I implement sleep function in my script . Do I really need to use 'flock' in my script or there is no need then. Thanks.
Re: Flock and Sleep
Sara wrote: (sub get_number { open(NUMBER,data.txt); flock (NUMBER, 2); Use the constants from the Fcntl module. Do blah blah blah close (NUMBER); closing a file automatically removes the lock?? Yes. or should I have to unlock it by placing flock (NUMBER, 8); close (NUMBER); No, you don't need to do that. In fact, it used to be dangerous, because of buffering. If you unlocked the file, buffered data could be written after the lock was released. Perl now automatically flushes the file before unlocking to avoid this. Bottom line: if you're going to close the file, don't worry about explicitly unlocking. You only need to unlock if you want to allow another process to gain the lock while you still hold the file open (i.e. coordinating changes to the file among multiple processes). My second question is how I can delay the execution of a script (If two users trying to execute the same script) for 30 sec by using sleep function? and If I implement sleep function in my script . Do I really need to use 'flock' in my script or there is no need then. If you want to make sure the two programs aren't changing the file simultaneously, you should use flock. If you dont' want to block forever if another process has the file locked, you need to use the LOCK_NB parameter and then sleep() or whatever until you want to retry the lock. Note that if multiple processes need to append to the file and each writes its data with individual calls to syswrite(), you don't need to use locking (although it doesn't really hurt anything). The kernel will perform individual writes atomically. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sockets and Sleep Question
On Thu, Oct 03, 2002 at 05:12:38PM -0700, Jessee Parker wrote: I will definitely take a look at this. How do you determine what your current nice status is? nice, with no arguments, will give you your current nice level. ps and top will diplay the nice level (or sometimes priority) of processes. Also, BSD::Resource, found on CPAN, has a method for retrieving a process's priority. I'm fairly certain there are more ways of getting the information. How did you verify the condition was never reached? If you determined it independently of the program printing to its log file then I'd have to see the code to be able to tell you what's going on. What I did was had top running and watched the load average. Ok, the test was seperate. Have you tried running strace on the program to see where it's sleeping? Are you certain it's sleeping, or is it possible it's blocking on a read or write? The code I am using to check the load average is this: $highload = .8; while (($currload = Load) $highload) { print LOG Sleeping\n; sleep 5; } sub Load { # Test system load and wait if it's too high @uptime = split(/,/, `uptime`); $fraction = $uptime[3]; $load = (split /:/, $fraction)[1]; return $load; } This code doesn't work for me, though it may be because of a difference in uptime output. Have you verified Load() returns the value you expect? Also, Load has slightly different meaning from Load(), due to the . It doesn't look like it will effect you here, but you should check perldoc perlsub for the difference between them. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sockets and Sleep Question
On Thu, Oct 03, 2002 at 10:10:34AM -0700, Jessee Parker wrote: At the top of the loop, I check the system uptime to get the load average so I can have the program sleep for 5 seconds to let things stabilize a bit. I suspect an easier way of doing this would be to nice yourself down really low; see man nice. There may be a Perl module available on CPAN for doing this, as well. When this happens, the message Sleeping is printed out to a log file. However, I noticed that the program ended up sleeping without printing the message. It sounds to me like you might be having a buffering issue; while the process did print before going to sleep, the output was never flushed to the file. See http://perl.plover.com/FAQs/Buffering.html. The condition I set for load average was never reached so there was no reason for it to sleep. I ran a netstat -an and there were alot of tcp connections to port 25 in the TIME_WAIT mode. How did you verify the condition was never reached? If you determined it independently of the program printing to its log file then I'd have to see the code to be able to tell you what's going on. What I'm trying to figure out is if the OS or Perl itself puts a limit on processes when it has a large number of connections in that mode forcing it to sleep. I am running this on Redhat Linux version 7.3. Unix operating systems do have methods of limiting the number of open file descriptors for a given process, as well as system-wide. However, the typical response when you reach this limit is to kill the offending process, not to put it to sleep. This is how Linux process limits operate. Perl doesn't impose limits on resource usage. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Sockets and Sleep Question
On Thu, Oct 03, 2002 at 10:10:34AM -0700, Jessee Parker wrote: At the top of the loop, I check the system uptime to get the load average so I can have the program sleep for 5 seconds to let things stabilize a bit. I suspect an easier way of doing this would be to nice yourself down really low; see man nice. There may be a Perl module available on CPAN for doing this, as well. I will definitely take a look at this. How do you determine what your current nice status is? When this happens, the message Sleeping is printed out to a log file. However, I noticed that the program ended up sleeping without printing the message. It sounds to me like you might be having a buffering issue; while the process did print before going to sleep, the output was never flushed to the file. See http://perl.plover.com/FAQs/Buffering.html. The condition I set for load average was never reached so there was no reason for it to sleep. I ran a netstat -an and there were alot of tcp connections to port 25 in the TIME_WAIT mode. How did you verify the condition was never reached? If you determined it independently of the program printing to its log file then I'd have to see the code to be able to tell you what's going on. What I did was had top running and watched the load average. The code I am using to check the load average is this: $highload = .8; while (($currload = Load) $highload) { print LOG Sleeping\n; sleep 5; } sub Load { # Test system load and wait if it's too high @uptime = split(/,/, `uptime`); $fraction = $uptime[3]; $load = (split /:/, $fraction)[1]; return $load; } The buffering information is great, but I will have to wait until the next run to see if that is indeed why Sleeping isn't being printed out. When I do local tests, I can print Sleeping to the screen with no problem. Even when I take out the LOG in the above, Sleeping does not get printed out with an actual run of data (an actual run being subscriber e-mail addresses versus e-mail accounts I have set up on various sites for testing). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sleep question
Greetings, I have a script that forks 5 children. I print to screen when each child gets forked. Under certain conditions in the script a child should sleep. This conditions occurs at different times for each child. I think I am noticing that when the sleep is called in a child, every child and the parent sleep as well. Am I correct in this assumption? The OS that the script is running on is Solaris. Thanks, CHad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sleep question
-Original Message- From: Chad Kellerman [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 12, 2002 12:37 PM To: [EMAIL PROTECTED] Subject: sleep question Greetings, I have a script that forks 5 children. I print to screen when each child gets forked. Under certain conditions in the script a child should sleep. This conditions occurs at different times for each child. I think I am noticing that when the sleep is called in a child, every child and the parent sleep as well. Am I correct in this assumption? No. After the fork, parent and child lead separate lives. Something else is going on. The OS that the script is running on is Solaris. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
print, sleep, print.....
While looking over the 'print over prior print' thread, I found that, as it should be, perl will print out as fast as it can. Below code #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; } So? Great, right? Well, what if I want to slow if down with a sleep() statement? #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; sleep(1); } From what I have done using perl 5.4.x, I was able to do things like this. But it seems that perl 5.6.0 will just sleep and not print anything out. Can someone explain why? And can some one explain how to slow the while loop down a bit if not using sleep()? Thanks! -James James Kelty Sr. Unix Systems Administrator The Ashland Agency 541.488.0801 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: print, sleep, print.....
Look at perldoc -q flush. On Fri, 2002-02-08 at 12:50, James Kelty wrote: While looking over the 'print over prior print' thread, I found that, as it should be, perl will print out as fast as it can. Below code #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; } So? Great, right? Well, what if I want to slow if down with a sleep() statement? #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; sleep(1); } From what I have done using perl 5.4.x, I was able to do things like this. But it seems that perl 5.6.0 will just sleep and not print anything out. Can someone explain why? And can some one explain how to slow the while loop down a bit if not using sleep()? Thanks! -James James Kelty Sr. Unix Systems Administrator The Ashland Agency 541.488.0801 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Today is Prickle-Prickle the 39th day of Chaos in the YOLD 3168 Missle Address: 33:48:3.521N 84:23:34.786W -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: print, sleep, print.....
I saw this too and immediately thought of flushing... Try adding this before you go into the while loop: $|++; Jason If memory serves me right, on Friday 08 February 2002 12:50, James Kelty wrote: While looking over the 'print over prior print' thread, I found that, as it should be, perl will print out as fast as it can. Below code #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; } So? Great, right? Well, what if I want to slow if down with a sleep() statement? #!/usr/bin/perl -w $count = 1; while(1) { $count++; print ${count}\r; sleep(1); } From what I have done using perl 5.4.x, I was able to do things like this. But it seems that perl 5.6.0 will just sleep and not print anything out. Can someone explain why? And can some one explain how to slow the while loop down a bit if not using sleep()? Thanks! -James James Kelty Sr. Unix Systems Administrator The Ashland Agency 541.488.0801 [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
perl sleep
I have been asked to rewrite a ftp process in perl on Win32. The program will scan a directory every five minutes and if a file exists, it will ftp the file to a server. My question is, has any had an experience using the Windows Task Scheduler to do a every 5 minute process or do you think it would be best to have perl sleep for 5 minutes? Thanks, -Scott -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl sleep
This used to be the method that MRTG used on a NT machine. The newer versions do not do this, so you will have to find older versions with docs that tell you how to do it. Actually, I remember there being an NT script, or little Perl program that added all of this for you. I got the following from this page, http://noc.nol.net/mirrors/mrtg/mrtg.html, which is an archive of some sort of older versions of the mrtg web site. The current page is www.mrtg.org. $interval=300; while (1) { sleep( $interval - time() % $interval ); system 'c:\bin\perl c:\mrtg-2.7.4\run\mrtg c:\mrtg-2.7.4\run\mrtg.cfg'; } Matthew J. Tisdel Service Resources, Inc. 864 272-2777 -Original Message- From: Scott [mailto:[EMAIL PROTECTED]] Sent: Monday, January 07, 2002 1:45 PM To: [EMAIL PROTECTED] Subject: perl sleep I have been asked to rewrite a ftp process in perl on Win32. The program will scan a directory every five minutes and if a file exists, it will ftp the file to a server. My question is, has any had an experience using the Windows Task Scheduler to do a every 5 minute process or do you think it would be best to have perl sleep for 5 minutes? Thanks, -Scott -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl sleep
Here a little daemon that runs my Perl FTP program with different job cards. It runs every 5 minutes. #!/usr/bin/perl -w use strict; use POSIX; # Start the loop for the daemon while(1) { my(@now) = localtime(); my($today) = POSIX::strftime( %m/%d/%Y, @now); my($time) = POSIX::strftime( %H:%M, @now); print Running 5 minute jobs | $today | $time\n; system ( 'perl newftp2.pl gep_card.xml' ); system ( 'perl newftp2.pl gel_card.xml' ); system ( 'perl newftp2.pl met_card.xml' ); system ( 'perl newftp2.pl nor_card.xml' ); system ( 'perl newftp2.pl pet_card.xml' ); system ( 'perl newftp2.pl th_jua_card.xml' ); system ( 'perl newftp2.pl th_del_card.xml' ); system ( 'perl newftp2.pl th_chi_card.xml' ); sleep 300; # 5 minute intervals } I used to do this with NT Scheduler (if you have to do it that way go to Advanced options and you can repeat every x minutes) but I found that the Perl daemon was easier. Also since my production box is my pc (ack) I don't have a MS Window popping up every 5 minutes like you will have with the scheduler. Hope this helps... Joel -Original Message- From: Scott [mailto:[EMAIL PROTECTED]] Sent: Monday, January 07, 2002 10:44 AM To: [EMAIL PROTECTED] Subject: perl sleep I have been asked to rewrite a ftp process in perl on Win32. The program will scan a directory every five minutes and if a file exists, it will ftp the file to a server. My question is, has any had an experience using the Windows Task Scheduler to do a every 5 minute process or do you think it would be best to have perl sleep for 5 minutes? Thanks, -Scott -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl sleep
Thank you to everyone for the help. I think the timer should be easy enough to implement in perl. My concern was memory usage with the NT task scheduler and would rather have perl do the chore. At 06:52 PM 1/7/2002 +, Stout, Joel R wrote: I used to do this with NT Scheduler (if you have to do it that way go to Advanced options and you can repeat every x minutes) but I found that the Perl daemon was easier. Also since my production box is my pc (ack) I don't have a MS Window popping up every 5 minutes like you will have with the scheduler. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sleep problem (which may cause insomnia...)
Hello All, I'm writing a program that will allow users to construct an email message and schedule when the message will be sent (eg for times when the mail server is less busy). I solved the scheduling program by subtracting the send time from the current time giving me X seconds to wait. Then I use sleep($pause_length) before the next part of the program--mailing--executes. However, I also want the user to receive a Web page that says, yeah, it worked. When I run the program, everything does work, except that the sleep() seems to invoke before the Web page is constructed. I'd be happy to hear if there is a better solution to this problem than sleep(), or why sleep() is preventing the page from being created. Here's the relevant code: $time_current = time(); $time_send = timelocal(0, 0, $hour, $day, $month-1, $year-1900); $pause_length = ($time_send - $time_current); if ($pause_length 0) { print $q-header( text/html ), $q-start_html( -title = Error ), $q-h2( Date and time problem ), $q-p( You have entered a date and/or time in the past. Please hit the Back button and try again. ), $q-end_html; exit; } else { print $q-header( text/html ), $q-start_html( -title = output ), $q-h2( Ouput ), $q-p( Here's what you wrote: $message ), $q-end_html; } mail(); exit; sub mail { sleep($pause_length); open SENDMAIL, | /usr/lib/sendmail -oi -t || die Can't fork for sendmail: $!\n; print SENDMAIL From: $sender_email \n; print SENDMAIL To: $sender_email \n; print SENDMAIL Bcc: @recipients; print SENDMAIL Reply-to: $reply_to \n; print SENDMAIL Subject: $subject \n; print SENDMAIL This messages is from: $sender_name, $sender_email\n; print SENDMAIL $message \n; close(SENDMAIL) || warn sendmail didn't close nicely; } * Lesli LaRocco Systems Administrator Ithaca College -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: How can I sleep and hundreds milliseconds, shorter than 1 second?
Time::HiRes is also good. It may be used for measuring time in msec -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sleep
Hi, I have a perl cgi script that works great. I want to put it into and endless loop, put my problem is that my page keeps adding onto it's self. How do I redisplay the web screen without it adding on to it? Thanks, Jerry
Re: sleep
On Fri, 22 Jun 2001, Jerry Preston wrote: I have a perl cgi script that works great. I want to put it into and endless loop, put my problem is that my page keeps adding onto it's self. How do I redisplay the web screen without it adding on to it? How are you doing this? You probably want the script to redirect to itself. Can you post some code? -- Brett http://www.chapelperilous.net/btfwk/ Soap and education are not as sudden as a massacre, but they are more deadly in the long run. -- Mark Twain
sleep () and print ()
I am apparently missing something. I used the following lines in a program, with the intention of the output to screen pausing 1 second, then printing 2 line returns and 'The result is:', then pausing another second, then continuing with the rest of the printing. What it does is pause one second, do the 2 line returns, wait another second, then do all the printing together. I obviously have something wrong, but don't know what. Section of code: sleep (1); print \n\nThe result is:; sleep (1); print \n\nI was home alone. etc, etc. -- Jim Gallott West Meadows Farm, New Haven VT [EMAIL PROTECTED] http://www.westmeadowsfarm.com
Re: sleep () and print ()
I am apparently missing something. Being aware of buffering, I suspect. Various parts of the 'pipe' between your print statements and the final destination do some sort of buffering. You can switch some of this off in perl by specifying: $| = 1;
Re: sleep () and print ()
Thank you. worked like a charm. On Saturday 16 June 2001 12:52, Me wrote: I am apparently missing something. Being aware of buffering, I suspect. Various parts of the 'pipe' between your print statements and the final destination do some sort of buffering. You can switch some of this off in perl by specifying: $| = 1; -- Jim Gallott West Meadows Farm, New Haven VT [EMAIL PROTECTED] http://www.westmeadowsfarm.com