Pause Perl Program?

Discussion in 'Perl Misc' started by still me, Jul 8, 2007.

  1. still me

    still me Guest

    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?
    still me, Jul 8, 2007
    #1
    1. Advertising

  2. still me

    Paul Lalli Guest

    On Jul 8, 8:33 am, still me <> wrote:
    > 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
    Paul Lalli, Jul 8, 2007
    #2
    1. Advertising

  3. still me

    still me Guest

    On Sun, 08 Jul 2007 05:44:41 -0700, Paul Lalli <>
    wrote:

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


    Thanks
    still me, Jul 8, 2007
    #3
  4. On Sun, 08 Jul 2007 12:33:10 GMT, still me <>
    wrote:

    >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
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Jul 8, 2007
    #4
  5. still me

    Bart Lateur Guest

    still me wrote:

    >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.

    --
    Bart.
    Bart Lateur, Jul 8, 2007
    #5
  6. still me

    Lambik Guest

    "still me" <> wrote in message
    news:...
    > 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
    Lambik, Jul 8, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Shohet
    Replies:
    10
    Views:
    1,902
    Kevin Spencer
    Jun 18, 2004
  2. Rick
    Replies:
    4
    Views:
    41,561
    Roedy Green
    Oct 8, 2003
  3. Amit Nath

    Pause a program while running

    Amit Nath, Jun 29, 2004, in forum: C Programming
    Replies:
    10
    Views:
    604
    Wynand Winterbach
    Jul 21, 2004
  4. Making a program pause

    , Dec 24, 2007, in forum: C Programming
    Replies:
    21
    Views:
    1,234
    Kelsey Bjarnason
    Jan 2, 2008
  5. Tuxedo
    Replies:
    7
    Views:
    419
    J. Gleixner
    Aug 16, 2012
Loading...

Share This Page