flushing output

If you expect characters to get to your device when you print() them, you'll want to autoflush that filehandle. You can use select() and the $| variable to control autoflushing (see perlvar/$| and perlfunc/select, or perlfaq5, ``How do I flush/unbuffer an output filehandle? Why must I do this?''):

    $oldh = select(DEV);
    $| = 1;
    select($oldh);
You'll also see code that does this without a temporary variable, as in

    select((select(DEV), $| = 1)[0]);
Or if you don't mind pulling in a few thousand lines of code just because you're afraid of a little $| variable:

    use IO::Handle;
    DEV->autoflush(1);
As mentioned in the previous item, this still doesn't work when using socket I/O between Unix and Macintosh. You'll need to hard code your line terminators, in that case.


Back to perlfaq8