IO::Bu...Select(3pm)
π IO::BufferedSelect β the manual page, but make it a group chat π
okay bestie, so this is the manual page for IO::BufferedSelect(3pm) (yes the header truncates it all cute like IO::Bu...Select(3pm), but we know her full name π
). Sit down, grab a strawberry π, and let's talk about reading from a whole bunch of filehandles at once without losing your entire mind.
β¨ NAME β¨
IO::BufferedSelect β Line-buffered select interface. that's it. that's the whole vibe. π¦
β¨ SYNOPSIS β¨
here's the moment you've been waiting for, the main character entrance π
use IO::BufferedSelect;
my $bs = new BufferedSelect($fh1, $fh2);
while(1)
{
my @ready = $bs->read_line();
foreach(@ready)
{
my ($fh, $line) = @$_;
my $fh_name = ($fh == $fh1 ? "fh1" : "fh2");
print "$fh_name: $line";
}
}
like. it's giving effortless. look at her go. π
β¨ DESCRIPTION β¨
so the select system call (and the IO::Select interface) is the girl who lets you process multiple streams at the same time, blocking until one or more of them is ready for reading or writing. iconic behavior. BUT π¨ there's a catch, and the catch is that she makes you use sysread and syswrite instead of Perl's buffered I/O functions. rude honestly.
and when we're talking about reading, combining select with readline gives you two whole problems:
selectmight block β but the data we want is already in Perl's input buffer, just sitting there, ready to be slurped in byreadline. πselectmight indicate that data is available, butreadlinewill block anyway because there isn't a full$/-terminated line available. π
so the whole purpose of this module? it implements a buffered version of the select interface that operates on lines, rather than characters. give her a set of filehandles and she will block until a full line is available on one or more of them. periodt. πΈ
β οΈ and now the fine print, bestie, listen up: this module is currently limited, in that (1) it only doesselectfor readability, not writability or exceptions; and (2) it does not support arbitrary line separators ($/) β lines must be delimited by newlines.
β¨ CONSTRUCTOR β¨
new ( HANDLES )β creates aBufferedSelectobject for a set of filehandles. and here's the important part, no cap: because this class buffers input from these filehandles internally, you should only use theBufferedSelectobject for reading from them. do NOT read from them directly, and do NOT pass them to other BufferedSelect instances. she's possessive like that π
β¨ METHODS β¨
read_lineread_line ($timeout)read_line ($timeout, @handles)
blocks until a line is available on one of the filehandles. if $timeout is undef, she blocks indefinitely; otherwise, she returns after at most $timeout seconds. β³
if @handles is specified, then only these filehandles will be considered; otherwise, she'll use all the filehandles you passed to the constructor. you pick, queen π
returns a list of pairs [$fh, $line], where $fh is a filehandle and $line is the line that was read (including the newline, ala readline). if the filehandle reached EOF, then $line will be undef. and ngl, "reached EOF" here is to be interpreted in the buffered sense: if a filehandle is at EOF but there are newline-terminated lines in BufferedSelect's buffer, read_line will continue to return lines until the buffer is empty. she finishes what she started. π
β¨ SEE ALSO β¨
IO::Selectβ the OG, go say hi π«Ά
β¨ AUTHOR β¨
Antal Novak, <afn@cpan.org> β we love you, icon π
β¨ COPYRIGHT AND LICENSE β¨
Copyright (C) 2007 by Antal Novak
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
and that's the whole page, bestie π perl v5.36.0, dated 2022-11-20, and yes the footer also calls her IO::Bu...Select(3pm) because even the manpage renderer couldn't handle all that name π now go forth and read your lines β¨π
π¦ where this page comes from
- debian bookworm: libio-bufferedselect-perl 1.0-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libio-bufferedselect-perl 1.0-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libio-bufferedselect-perl 1.0-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libio-bufferedselect-perl 1.0-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libio-bufferedselect-perl 1.0-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms