develooper Front page | perl.perl5.porters | Postings from April 2003

[perl #21833] problems with pack

Thread Next
From:
Daniel Sayko via RT
Date:
April 4, 2003 14:06
Subject:
[perl #21833] problems with pack
Message ID:
rt-21833-54552.3.21120981159389@bugs6.perl.org

<URL: http://rt.perl.org/rt2/Ticket/Display.html?id=21833 >

I have found that version 5.8.0 differs from 5.6.1 and 5.005_03 in the results returned from pack.  I'm curious if I missed a change I'm suppose to do, or if there is an actual bug in Perl 5.8.0.  The problem I'm having is when I pack a number into an integer, for any octet > 0x7F, it is being preceded by 0xC2.  This of course causes problems later when I have other programs interpret the packed int.  I have reduced the code problem into a tiny example.

Here is my code:
#!/usr/bin/perl

my $value = 131;

my $val1 = pack("N", $value);
my $val2 = unpack("N", $val1);

print $value." ".$val1." ".$val2."\n";

Here is are my results:
==========  Version 5.005_03  ===============
$ ./pack.pl > junk
$ od -t x1 junk
0000000 31 33 31 20 00 00 00 83 20 31 33 31 0a
0000015
$

==========  Version 5.6.1  ==================
$ ./pack.pl > junk
$ od -t x1 junk
0000000 31 33 31 20 00 00 00 83 20 31 33 31 0a
0000015
$ 

==========  Version 5.8.0  ==================
$ ./pack.pl > junk
$ od -t x1 junk
0000000 31 33 31 20 00 00 00 c2 83 20 31 33 31 0a
0000016
$


Notice the extra octet in 5.8.0.

-- Thanks,
Daniel




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About