发信人: saka.bbs@bbs.neu.edu.cn (机器猫), 信区: cnlinux
标  题: perl(31)
发信站: 白山黑水BBS (Wed Apr  2 17:45:48 1997)
转信站: Lilac!ustcnews!ustcnews!sjtunews!neubbs
出  处: conger.neu.edu.cn

--------------19392C2CC81
Content-Type: text/plain; charset=us-ascii; name="select.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="select.txt"

NAME

select - reset default output or do I/O multiplexing

---------------------------------------------------------------------------

SYNOPSIS

select FILEHANDLE

select

select RBITS,WBITS,EBITS,TIMEOUT

---------------------------------------------------------------------------

DESCRIPTION

Returns the currently selected filehandle. Sets the current default
filehandle for output, if FILEHANDLE is supplied. This has two effects:
first, a write or a print without a filehandle will default to this
FILEHANDLE. Second, references to variables related to output will refer to
this output channel. For example, if you have to set the top of form format
for more than one output channel, you might do the following:

    select(REPORT1);
    $^ = 'report1_top';
    select(REPORT2);
    $^ = 'report2_top';

FILEHANDLE may be an expression whose value gives the name of the actual
filehandle. Thus:

    $oldfh = select(STDERR); $| = 1; select($oldfh);

Some programmers may prefer to think of filehandles as objects with
methods, preferring to write the last example as:

    use FileHandle;
    STDERR->autoflush(1);

This calls the select(2) system call with the bitmasks 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;

If you want to select on many filehandles you might wish to write a
subroutine:

    sub fhbits {
        local(@fhlist) = split(' ',$_[0]);
        local($bits);
        for (@fhlist) {
            vec($bits,fileno($_),1) = 1;
        }
        $bits;
    }
    $rin = fhbits('STDIN TTY SOCK');

The usual idiom is:

    ($nfound,$timeleft) =
      select($rout=$rin, $wout=$win, $eout=$ein, $timeout);

or to block until something becomes ready:

    $nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);

Any of the bitmasks can also be undef. The timeout, if specified, is in
seconds, which may be fractional. Note: not all implementations are capable
of returning the $timeleft. If not, they always return $timeleft equal to
the supplied $timeout.

You can effect a 250-microsecond sleep this way:

    select(undef, undef, undef, 0.25);

WARNING: Do not attempt to mix buffered I/O (like read() or <FH>) with
select() . You have to use sysread() instead.

--------------19392C2CC81--

--
※ 来源:.白山黑水站 bbs.neu.edu.cn.[FROM: ygh@rose.dlut.edu.cn]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.864毫秒