Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:

All:
Is there anything evil about the following:

#!/usr/bin/perl -w use strict; print "awake\n"; select(undef,undef,undef,.75); print "awake\n";

Using the 4 arg select to sleep for sub 1 second intervals without Time::HiRes.

I am strictly asking if there is anything wrong with it. I came across it and thought it was neat and do not think it is an excuse not to use Time::HiRes.

Thanks - L~R

Replies are listed 'Best First'.
Re: 4 arg select as an alternative to Time::HiRes ?
by IlyaM (Parson) on Mar 01, 2003 at 22:39 UTC
Re: 4 arg select as an alternative to Time::HiRes ?
by Abigail-II (Bishop) on Mar 02, 2003 at 12:31 UTC
    Your really don't have to excuse yourself for not using Time::HiRes. Time::HiRes was only a recent addition to the core anyway. Furthermore, if you look into the XS file, you'll notice that depending on what's available on your platform, Time::HiRes may fall back on select anyway.

    Abigail

Re: 4 arg select as an alternative to Time::HiRes ?
by crenz (Priest) on Mar 01, 2003 at 23:19 UTC

    Well, it's definitely not evil, but for someone like me who is not so well-versed in Unix system calls or whatever select does, the Time::HiRes variant is much more self-documenting :)

Re: 4 arg select as an alternative to Time::HiRes ?
by Aristotle (Chancellor) on Mar 02, 2003 at 01:04 UTC
    You could also try this for size:
    BEGIN { *CORE::sleep = sub(;$) { select((undef)x3, shift) } } sleep 0.75;

    Makeshifts last the longest.

      I can never get select to accept (undef)x3,$time?

      I also found that substr won't accept an array for its argument list either?


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.
        $ perl -le'print for prototype("CORE::substr"), prototype("CORE::selec +t")' $$;$;$ ;*

        You are right about substr. Unfortunately, select seems to have some special magic; even the error message you get is unique to it.

        One more thing to remember..

        Makeshifts last the longest.