Home
Search Perl pages
Subjects
By activity
Professions, Sciences, Humanities, Business, ...
User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...
Text Strings
Conversions, tests, processing, manipulation,...
Math
Integer, Floating point, Matrix, Statistics, Boolean, ...
Processing
Algorithms, Memory, Process control, Debugging, ...
Stored Data
Data storage, Integrity, Encryption, Compression, ...
Communications
Networks, protocols, Interprocess, Remote, Client Server, ...
Hard World Timing, Calendar and Clock, Audio, Video, Printer, Controls...
File System
Management, Filtering, File & Directory access, Viewers, ...
|
|
|
select FILEHANDLE
select
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 IO::Handle;
STDERR->autoflush(1);
select RBITS,WBITS,EBITS,TIMEOUT
This calls the select(2) system call 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;
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 just do this
$nfound = select($rout=$rin, $wout=$win, $eout=$ein, undef);
Most systems do not bother to return anything useful in $timeleft, so
calling select() in a scalar context just returns $nfound.
Any of the bit masks 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 sleep of 250 milliseconds 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.
Source: Perl builtin functions Perl builtin functions Copyright: Larry Wall, et al. |
Next: semctl ID,SEMNUM,CMD,ARG Next: select RBITS,WBITS,EBITS,TIMEOUT
Previous: select FILEHANDLE Previous: seekdir DIRHANDLE,POS
(Corrections, notes, and links courtesy of RocketAware.com)
Up to: Socket and I/O Operations Up to: File Access
Rapid-Links:
Search | About | Comments | Submit Path: RocketAware > Perl >
perlfunc/select.htm
RocketAware.com is a service of Mib Software Copyright 2000, Forrest J. Cavalier III. All Rights Reserved. We welcome submissions and comments
|