Pause Perl Program?

S

still me

Newbieish question: I have a program that I need to have pause for a
second (or less), then continue.

I RTFM'ed and I found the Sleep function and Win32::Sleep. It seems
like the Win32::Sleep module is a better choice as it allows
millisecond intervals where as the Sleep module only accepts full
seconds. This program will run only on Windows. I also found
Time::HiRes but that looks like overkill for what I need to do this
time.

Do I have this correct? Are there other functions that pause? Any
subtleties I need to know about?
 
P

Paul Lalli

Newbieish question: I have a program that I need to have pause for a
second (or less), then continue.

I RTFM'ed and I found the Sleep function and Win32::Sleep. It seems
like the Win32::Sleep module is a better choice as it allows
millisecond intervals where as the Sleep module only accepts full
seconds. This program will run only on Windows. I also found
Time::HiRes but that looks like overkill for what I need to do this
time.

Do I have this correct? Are there other functions that pause? Any
subtleties I need to know about?

$ perldoc -q sleep
Found in /software/perl-5.8.5-0/pkg/lib/5.8.5/pod/perlfaq8.pod
How can I sleep() or alarm() for under a second?

If you want finer granularity than the 1 second that the
sleep() function provides, the easiest way is to use the
select() function as documented in "select" in perlfunc.
Try the Time::HiRes and the BSD::Itimer modules (available
from CPAN, and starting from Perl 5.8 Time::HiRes is part of
the standard distribution).

I see no reason to download a non-core non-portable module for such a
simple task.

Paul Lalli
 
M

Michele Dondi

seconds. This program will run only on Windows. I also found
Time::HiRes but that looks like overkill for what I need to do this

Why an overkill? It's also a core module now...


Michele
 
B

Bart Lateur

still said:
I RTFM'ed and I found the Sleep function and Win32::Sleep. It seems
like the Win32::Sleep module is a better choice as it allows
millisecond intervals where as the Sleep module only accepts full
seconds. This program will run only on Windows. I also found
Time::HiRes but that looks like overkill for what I need to do this
time.

But Time::HiRes comes with perl.

Alternatively, you can try using the 4 argument select() call to produce
a sleep-like effect. That even doesn't need a module.
 
L

Lambik

still me said:
Do I have this correct? Are there other functions that pause? Any
subtleties I need to know about?

Is this like a JAPH? Who can come up with the most useless sleep? How about:

use strict;
use warnings;
use Win32::API;

my $Handler = Win32::API->new( 'kernel32', 'Sleep', 'L', 'V');
$Handler->Call (10000); # Milliseconds
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top