sysopen
and O_RDWR|O_NDELAY|O_NOCTTY
from the Fcntl module (part of the standard perl distribution). See
sysopen for more on this approach.
print DEV "atv1\012"; # wrong, for some devices print DEV "atv1\015"; # right, for some devices
Even though with normal text files, a ``\n'' will do the trick, over the network, there is still no unified scheme for terminating a line that is cross-platform to all of Unix, DOS/Win, and Macintosh, except to terminate ALL line ends with ``\015\012'', and strip what you don't need from the output. This applies especially to socket I/O and autoflushing, discussed next.
print
them, you'll want to autoflush that filehandle, as in the older
use FileHandle; DEV->autoflush(1);
and the newer
use IO::Handle; DEV->autoflush(1);
You can use select
and the $|
variable to control autoflushing (see $| and select):
$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]);
As mentioned in the previous item, this still doesn't work when using socket I/O between Unix and Macintosh. You'll need to hardcode your line terminators, in that case.
read
or sysread,
you'll have to arrange for an alarm handler to provide a timeout (see
alarm). If you have a non-blocking open, you'll likely have a non-blocking read, which means you may have to use a 4-arg select
to determine whether
I/O is ready on that device (see
select.