Discussion:
binmode failing with 5.8.4
(too old to reply)
lttteam
2005-11-24 12:14:39 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 - Nw 6.5, SP2, Perl version 5.8.0 -
seems to be working all fine with the code snippet I have here...

I saw a discussion thread where others had seen the same problem, and it
appears that novel developers had fixed it. Would anybody know what/where
the fix was so that I can take appropriate source and try building Perl
again..

Please help!!!!

Thanks,
Gopa
Guenter Knauf
2005-11-24 16:50:12 UTC
Permalink
Hi Gopa,
Post by lttteam
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.
wouh! I was always to stupid for that; where did you compile? Linux? what
linker/compiler?

I will ask the developers about your issue.

Guenter.
Post by lttteam
$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 - Nw 6.5, SP2, Perl version 5.8.0 -
seems to be working all fine with the code snippet I have here...
I saw a discussion thread where others had seen the same problem, and it
appears that novel developers had fixed it. Would anybody know what/where
the fix was so that I can take appropriate source and try building Perl
again..
Please help!!!!
Thanks,
Gopa
lttteam
2005-11-25 11:55:01 UTC
Permalink
Hi Guenter,
I compiled with CodeWarrior (cross)compiler. Had a tough time trying to
get a static lib out of the source code, and to get it to link to my app..
Incidentally, I have perl compiled on several other platforms
(hp-ux/windows/ovms/tru64/linux) and only NW seems to be mis-behaving :(

Any advice/help to get around this issue will be deeply appreciated.

thanks,
Gopa
Post by Guenter Knauf
Hi Gopa,
Post by lttteam
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.
wouh! I was always to stupid for that; where did you compile? Linux? what
linker/compiler?
I will ask the developers about your issue.
Guenter.
Post by lttteam
$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 - Nw 6.5, SP2, Perl version 5.8.0
-
Post by lttteam
seems to be working all fine with the code snippet I have here...
I saw a discussion thread where others had seen the same problem, and it
appears that novel developers had fixed it. Would anybody know what/where
the fix was so that I can take appropriate source and try building Perl
again..
Please help!!!!
Thanks,
Gopa
Guenter Knauf
2005-11-25 18:22:25 UTC
Permalink
Hi Gopa,
Post by lttteam
I compiled with CodeWarrior (cross)compiler. Had a tough time trying to
get a static lib out of the source code, and to get it to link to my
app.. Incidentally, I have perl compiled on several other platforms
(hp-ux/windows/ovms/tru64/linux) and only NW seems to be mis-behaving :(
hehe...
Post by lttteam
Any advice/help to get around this issue will be deeply appreciated.
I asked already, but dont expect an answer before monday...
However if you know where the fopen() happens in the code there should
already be a '#ifdef WIN32' case for since that OS also needs binmode;
normally its sufficient to change that ifdef.

Guenter.
KMurugan
2005-11-28 05:41:05 UTC
Permalink
Hi All,

I checked in Perl 5.8.4 (LIBC based) which is getting delivered to
latest support pack (Tested in OES-SP2 & SP1) and found that it is
working fine.

Gopa built Perl 5.8.4 using CLIB for his custom application where he
fixed the problem by replacing fsetmode instead of setmode() to fix
the binmode problem.

Gopa! Have a nice sleep. Is there any specific reason to build Perl
5.8.4 using CLIB.

Regards
K.Murugan
Post by Guenter Knauf
Hi Gopa,
Post by lttteam
I compiled with CodeWarrior (cross)compiler. Had a tough time trying to
get a static lib out of the source code, and to get it to link to my
app.. Incidentally, I have perl compiled on several other platforms
(hp-ux/windows/ovms/tru64/linux) and only NW seems to be mis-behaving :(
hehe...
Post by lttteam
Any advice/help to get around this issue will be deeply appreciated.
I asked already, but dont expect an answer before monday...
However if you know where the fopen() happens in the code there should
already be a '#ifdef WIN32' case for since that OS also needs binmode;
normally its sufficient to change that ifdef.
Guenter.
lttteam
2005-11-28 11:18:29 UTC
Permalink
Hello Murugan,
I had to build Perl on CLIB because my app was CLIB based!! And I needed
to build the source since I wanted to link Perl statically to my app (and
not use the Perl version that would have come with the OS)..

Thanks Murugan and Guenter for your help with this issue!

Gopa
Post by KMurugan
Hi All,
I checked in Perl 5.8.4 (LIBC based) which is getting delivered to
latest support pack (Tested in OES-SP2 & SP1) and found that it is
working fine.
Gopa built Perl 5.8.4 using CLIB for his custom application where he
fixed the problem by replacing fsetmode instead of setmode() to fix
the binmode problem.
Gopa! Have a nice sleep. Is there any specific reason to build Perl
5.8.4 using CLIB.
Regards
K.Murugan
Post by Guenter Knauf
Hi Gopa,
Post by lttteam
I compiled with CodeWarrior (cross)compiler. Had a tough time trying to
get a static lib out of the source code, and to get it to link to my
app.. Incidentally, I have perl compiled on several other platforms
(hp-ux/windows/ovms/tru64/linux) and only NW seems to be mis-behaving :(
hehe...
Post by lttteam
Any advice/help to get around this issue will be deeply appreciated.
I asked already, but dont expect an answer before monday...
However if you know where the fopen() happens in the code there should
already be a '#ifdef WIN32' case for since that OS also needs binmode;
normally its sufficient to change that ifdef.
Guenter.
Loading...