select undef, undef, undef .XX

perl

Solution

In the documentation for `select`, it is described like this:

...
select RBITS,WBITS,EBITS,TIMEOUT
        This calls the select(2) syscall with the bit masks specified,
        which can be constructed using "fileno" and "vec", along these
        lines:

            $rin = $win = $ein = '';
            vec($rin, fileno(STDIN),  1) = 1;
            vec($win, fileno(STDOUT), 1) = 1;
            $ein = $rin | $win;
...

Presumably this is just an arbitrary command with a timeout that has a higher precision than `sleep`. Which is why it works. This is also mentioned further down in the documentation:

You can effect a sleep of 250 milliseconds this way:

    select(undef, undef, undef, 0.25);

TL;DR: It's a way to call the `select` function with a timeout.

Problem

When I was initially learning Perl several years ago I found myself wanting to say something like: ``` sleep .07; ``` But this doesn't actually work. Someone taught me to use: ``` select undef, undef, undef, .07; ``` instead. I've always wondered: What does this mean, and why does it work?

Original source