Discussion:
Binmode in NetWare
(too old to reply)
Gopakumar Ambat
2005-11-24 11:34:20 UTC
Permalink
Hi,
I am running into an issue with Perl 5.8.4 (downloaded the source from
cpan and compiled for NetWare) while writing hex data to file.

My code snippet is:
$a_Number = 1034;
$a_HexNum = sprintf("%8X",$a_Number);
$a_Packed = pack("H*",$a_HexNum);

open($fd, "> sys:\\pack.dat");
binmode ($fd);
print $fd $a_Packed;
close ($fd);

The output of this (in binary format) is 00 00 04 0D 0A instead of 00 00
04 0A.

The "additional" 0D is coming because Perl seems to be treating 0A as a
linefeed and adding a carriage return (0x0D) to it.. binmode was
supposed to prevent this, any idea what's going wrong here? I tried
opening with different modes ("bytes", "raw"), but nothing seems to be
working...

(The Perl binary that comes with the OS seems to be working all fine
with the code snippet I have here...)


Please help!!!!

Thanks,
Gopa
Sisyphus
2005-11-25 07:43:46 UTC
Permalink
----- Original Message -----
From: "Ambat, Gopakumar (STSD)"
.
.
Post by Gopakumar Ambat
The "additional" 0D is coming because Perl seems to be treating 0A as a
linefeed and adding a carriage return (0x0D) to it.. binmode was
supposed to prevent this
Yes, binmode should prevent the 0x0D being written to file - at least it
does on my perl 5.8.4 on Win32.
Not sure that this is the most appropriate place to ask about this. Try
perlmonks or comp.lang.perl.misc if you don't get a satisfactory answer
here. Perhaps someone there has a similar experience and can help out.

Best to provide a complete, functional, (though minimal) script that
demonstrates the problem - rather than a snippet. You're snippet doesn't
demonstrate how you've managed to verify that the file does, indeed, contain
a 0x0D. And perhaps, in checking the value on the file, you've done
something improper. Without a complete script, no-one can know exactly what
you have done.

Cheers,
Rob

Loading...