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


In reply to Re: Is the documentation for Perl 5.20 'pack' correct? by flexvault
in thread Is the documentation for Perl 5.20 'pack' correct? by flexvault

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.