Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Is the documentation for Perl 5.20 'pack' correct?

by flexvault (Monsignor)
on Jul 07, 2015 at 23:12 UTC ( [id://1133657]=note: print w/replies, xml ) Need Help??


in reply to Is the documentation for Perl 5.20 'pack' correct?

Dear Monks,

I have the following script which I ran on 2 different machines:

#!/usr/local/bin/perl # use strict; use warnings; use Config; print "Byte order: $Config{byteorder}\n"; # expect byteorder='43 +21' or '1234'; my $hexstring = "01020304"; # Hex number my $decnumber = hex $hexstring; print "Hex: $hexstring is Dec: $decnumber\n"; # expect 1690 +9060 my $netnumber = pack( "N", $decnumber ); print "Dec: $decnumber is 'N': '",unpack("H8",$netnumber),"' as Ne +twork or Big-endian\n"; my $Nonnetnumber = pack( "V", $decnumber ); # Vax or little-e +ndian print "Dec: $decnumber is 'V': '",unpack("H8",$Nonnetnumber),"' as + Vax or Little-endian\n"; $Nonnetnumber = pack( "L", $decnumber ); # as native format print "Dec: $decnumber is 'L': '",unpack("H8",$Nonnetnumber),"' as + native format\n";
The results were:
On Aix 5.2 on RS/6000 ( powerpc-ibm-aix5.2.0.0 ) # pyrperl ./pack.pl Byte order: 4321 Hex: 01020304 is Dec: 16909060 Dec: 16909060 is 'N': '01020304' as Network or Big-endian Dec: 16909060 is 'V': '04030201' as Vax or Little-endian Dec: 16909060 is 'L': '01020304' as native format On Debian Linux on 64bit AMD ( Debian 4.4.5-8 ) # pyrperl ./pack.pl Byte order: 1234 Hex: 01020304 is Dec: 16909060 Dec: 16909060 is 'N': '01020304' as Network or Big-endian Dec: 16909060 is 'V': '04030201' as Vax or Little-endian Dec: 16909060 is 'L': '04030201' as native format
The results agree with Writing endian-independent code in C. My knowledge of big-endian came from writing machine to machine transfer software for IBM in the '70s.

The background was that IBM 32-bit mainframes were big-endian and expensive, and the new in-expensive (???) 8-bit boxes were little-endian.

As you can see the 'N' and 'V' 'pack' formats are the same on both architectures but the native formats are different. Perl's 'pack' is correct, but the documentation examples are incorrect.

Regards...Ed

"Well done is better than well said." - Benjamin Franklin

Replies are listed 'Best First'.
Re^2: Is the documentation for Perl 5.20 'pack' correct?
by Anonymous Monk on Jul 07, 2015 at 23:27 UTC
    what examples? can you produce a patch for pelfunc pointing out the wrongs?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1133657]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-18 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found