Ask a Question related to PERL Miscellaneous, Design and Development.
-
kernal32 #1
looping every x seconds
Hello,
In PERL how do I execute a block of code every "x" seconds?
I'm talking a loop or similar but it runs every x seconds, where x is given.
kernal32 Guest
-
Quotes that appear every few seconds
I am using dreamweaver and want to create a small side window on the page where short text quotes appear. The quotes need to change every 5-10... -
COM+ times out after 30 seconds.
I have a web service, that calls a COM + ( Queued). The COM+ runs a stored procedure in Sql Server. Now this strored procedure is to run for 6 hrs... -
2 seconds
hiya! check this: only the banks know about this, but it will save you a fortune are you prepared for lower mortgage repayments? ... -
ls showing seconds?
Hi all! Is there any way that ls show timestamps with seconds (i.e. format hh:mm:ss)? If not ls, maybe there is another command... ... -
format # of seconds to hh:mm
I am trying to trick some Infromix SQL command, so it will format the output of a query into the HH:MM. Say, a row data value 70 will be print as... -
kernal32 #2
Re: looping every x seconds
Sorry I didnt think I was clear.> Hello,
>
> In PERL how do I execute a block of code every "x" seconds?
> I'm talking a loop or similar but it runs every x seconds, where x is
> given.
I'm using sleep 5 to wait 5 second before executing some code.
my question is, how can I keep the rest of the program running whilst the
loop continues in pararel
kernal32 Guest
-
Purl Gurl #3
Re: looping every x seconds
kernal32 wrote:
> In PERL how do I execute a block of code every "x" seconds?
> I'm talking a loop or similar but it runs every x seconds,
> where x is given.
If "x" is not given, you cannot do this, yes?
#!perl
print "Press Control C To Stop Looping\n";
while (1)
{
print "Purl Gurl Rocks And Rolls!\r";
sleep (1);
}
Purl Gurl
Purl Gurl Guest
-
James Willmore #4
Re: looping every x seconds
On Wed, 10 Sep 2003 10:57:28 +0800
kernal32 <surakshan@removethisYahooRemove.com> wrote:Use fork. That's just one suggestion.>> > In PERL how do I execute a block of code every "x" seconds?
> > I'm talking a loop or similar but it runs every x seconds, where x
> > is given.
> Sorry I didnt think I was clear.
> I'm using sleep 5 to wait 5 second before executing some code.
>
> my question is, how can I keep the rest of the program running
> whilst the loop continues in pararel
==untested==
#!/usr/bin/perl -w
use strict;
my $child = fork();
die "Can't fork: $!\n" unless defined $child;
if($child > 0){
#parent process
}else{
$child process
}
You'll need to add some signal handlers and maybe use some POSIX
fuctionality. Basically, 'salt to taste' ;)
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
for more information.
a fortune quote ...
If you think the United States has stood still, who built the
<largest shopping center in the world? -- Richard M. Nixon
James Willmore Guest
-
James Willmore #5
Re: looping every x seconds
On Wed, 10 Sep 2003 05:01:54 GMT
James Willmore <jwillmore@cyberia.com> wrote:should be:> $child process
#child process
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. [url]http://www.gnu.org/licenses/gpl.txt[/url]
for more information.
a fortune quote ...
Only adults have difficulty with childproof caps.
James Willmore Guest
-
Randal L. Schwartz #6
Re: looping every x seconds
>>>>> "kernal32" == kernal32 <surakshan@removethisYahooRemove.com> writes:
kernal32> I'm using sleep 5 to wait 5 second before executing some
kernal32> code.
kernal32> my question is, how can I keep the rest of the program
kernal32> running whilst the loop continues in pararel
A simple way is to insert a check into your main loop:
my $next_time = time + 5;
while (1) {
if (time > $next_time) {
... do your once every five seconds thing here ..
$next_time = time + 5;
}
... rest of code ...
}
If other things are event-driven, consider POE, found in the CPAN,
and described at [url]http://poe.perl.org/[/url].
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz Guest
-
Jürgen Exner #7
Re: looping every x seconds
kernal32 wrote:
That is not possible from Perl.> In PERL how do I execute a block of code every "x" seconds?
> I'm talking a loop or similar but it runs every x seconds, where x is
> given.
You can put your the Perl program to rest for x seconds using sleep(). But
this is different from running the loop every x seconds.
Just imagine it takes y seconds to run the loop. Then the next start of the
loop will happen x+y seconds after the previous start.
If you really want/need to run the code every x seconds then you may need to
set up an external timer (depending on your needs for precision could be
another program or a system task or a hardware timer) which sends a signal
to your program and thus triggers the loop.
jue
Jürgen Exner Guest
-
Anno Siegel #8
Re: looping every x seconds
Jürgen Exner <jurgenex@hotmail.com> wrote in comp.lang.perl.misc:
Why on earth not?> kernal32 wrote:>> > In PERL how do I execute a block of code every "x" seconds?
> > I'm talking a loop or similar but it runs every x seconds, where x is
> > given.
> That is not possible from Perl.
What's stopping you from looking how long it took and subtracting that> You can put your the Perl program to rest for x seconds using sleep(). But
> this is different from running the loop every x seconds.
> Just imagine it takes y seconds to run the loop. Then the next start of the
> loop will happen x+y seconds after the previous start.
from the sleep time? Or something equivalent, more robust? Within
the precision of the timer, it is quite possible to run a Perl loop
at specified intervals.
Anno
Anno Siegel Guest



Reply With Quote

