Gopakumar Ambat
2005-11-24 11:34:20 UTC
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
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