Prev: FAQ 8.10 How do I read and write the serial port?
Next: FAQ 4.71 How do I handle binary data correctly?
From: Peter J. Holzer on 14 Jan 2010 03:31 On 2010-01-14 02:19, Ben Morrow <ben(a)morrow.me.uk> wrote: > Quoth "Peter J. Holzer" <hjp-usenet2(a)hjp.at>: >> Maybe a function "flush that stream before reading from this stream". Or >> - even more generic - just a hook which is called for certain ops. So >> you could do something like >> >> $in->add_hook(pre_read => sub { $out->flush }); > > This is called a 'PerlIO layer'. Duh! You are right of course. I haven't thought of that. (I did think of subclassing IO::Handle, but I couldn't figure out how to make STDOUT use the new class). hp
From: Ben Morrow on 14 Jan 2010 04:25 Quoth "Peter J. Holzer" <hjp-usenet2(a)hjp.at>: > On 2010-01-14 02:19, Ben Morrow <ben(a)morrow.me.uk> wrote: > > Quoth "Peter J. Holzer" <hjp-usenet2(a)hjp.at>: > >> Maybe a function "flush that stream before reading from this stream". Or > >> - even more generic - just a hook which is called for certain ops. So > >> you could do something like > >> > >> $in->add_hook(pre_read => sub { $out->flush }); > > > > This is called a 'PerlIO layer'. > > Duh! You are right of course. I haven't thought of that. (I did think of > subclassing IO::Handle, but I couldn't figure out how to make STDOUT use > the new class). IO::Handle is a disgusting hack. I expect it could be done, but it wouldn't be easy: an IO::Handle is a blessed glob containing a tied filehandle, so you would have to tie *main::STDOUT{IO} and then either (re)bless *main::STDOUT or assign it into a new glob which could be blessed. You could also, of course, tie STDOUT directly. I have never really understood why it appears to have been necessary for Perl to end up with three different systems for attaching magic to filehandles, none of which quite works right. Ben
First
|
Prev
|
Pages: 1 2 3 Prev: FAQ 8.10 How do I read and write the serial port? Next: FAQ 4.71 How do I handle binary data correctly? |