perllearner has asked for the wisdom of the Perl Monks concerning the following question:

i am new to sysread. trying to get a sysread return from a display device before sending more data into it. I should be expecting from the device values in hex such as FE or FF depending on whether the buffer is full or empty. But its returning garbage characters.
.. my $myBuf; my $selector = IO::Select->new(\*DisplayIO); if ($selector->can_read(3)) { # 3 second timeout. sysread (DisplayIO, $myBuf, 1); print "Buffer returned : $myBuf\n" } else { print "Nothing in buffer\n"; } ..
$myBuf is returning values such as þ & ÿ. I am hoping to get a hex return FE or FF. Thanks in advance.

Replies are listed 'Best First'.
Re: sysread returning weird values
by Zaxo (Archbishop) on Jun 17, 2004 at 23:33 UTC

    You're getting what you expect:

    $ perl -e'print ord("þ"), $/' 254 $ perl -e'print ord("ÿ"), $/' 255 $

    After Compline,
    Zaxo

Re: sysread returning weird values
by Ido (Hermit) on Jun 17, 2004 at 23:51 UTC
    You might want to try:
    print "Buffer returned : ". unpack('H*',$myBuf) . "\n";