Perl 选择undef、undef、undef.XX

Perl 选择undef、undef、undef.XX,perl,Perl,几年前,当我开始学习Perl时,我发现自己想说: sleep .07; 但这实际上不起作用 有人教我使用: select undef, undef, undef, .07; 相反 我一直在想: 这意味着什么,为什么它会起作用 在中,描述如下: ... select RBITS,WBITS,EBITS,TIMEOUT This calls the select(2) syscall with the bit masks specified, which can

几年前,当我开始学习Perl时,我发现自己想说:

sleep .07;
但这实际上不起作用

有人教我使用:

select undef, undef, undef, .07;
相反

我一直在想: 这意味着什么,为什么它会起作用

在中,描述如下:

...
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;
...
这可能只是一个具有超时的任意命令,其精度高于
sleep
。这就是它起作用的原因。文件中还进一步提到了这一点:

You can effect a sleep of 250 milliseconds this way:

    select(undef, undef, undef, 0.25);
TL;DR:这是一种调用带有超时的
选择
函数的方法。

在中,描述如下:

...
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;
...
这可能只是一个具有超时的任意命令,其精度高于
sleep
。这就是它起作用的原因。文件中还进一步提到了这一点:

You can effect a sleep of 250 milliseconds this way:

    select(undef, undef, undef, 0.25);

TL;DR:这是一种调用带有超时的
select
函数的方法。

使用第三种形式的

这将使用指定的位掩码调用
select(2)
syscall

....
您可以通过以下方式实现250毫秒的睡眠:

    select(undef, undef, undef, 0.25);
实现此功能的更好方法是使用


使用第三种形式的文件:

这将使用指定的位掩码调用
select(2)
syscall

....
您可以通过以下方式实现250毫秒的睡眠:

    select(undef, undef, undef, 0.25);
实现此功能的更好方法是使用


为什么
Time::HiRes
更好?因为以后阅读代码的人不必来问它做什么。:)为什么
Time::HiRes
更好?因为以后阅读代码的人不必来问它做什么。:)