I'd concur that the docs are misleading, if not outright wrong:

#! perl -slw use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'END_C', NAME => 'Endian', CLEAN_AFTER_BUILD =>0; SV *hexDump( UV in ) { int i; char *p = (char*)&in; SV *out = newSVpvn( NULL, 0 ); for( i=0; i<8; ++i ) { sv_catpvf( out, "%02x", p[i] ); } return out; } END_C print hexDump( 72623859790382856 ); __END__ C:\test>endian Use of uninitialized value in subroutine entry at C:\test\endian.pl li +ne 19. 0807060504030201

(Aside: If anyone groks why I get the uninitialized value in subroutine entry warning; please enlighten me?)

But you have to factor in the context and tools you use to display the results.

For example, the first two below clearly demonstrate big and little endian respectively; the rest show how easy it is to get misleading results:

C:\test>p1 [0] Perl> print unpack 'C*', pack 'Q>', 72623859790382856;; 1 2 3 4 5 6 7 8 [0] Perl> print unpack 'C*', pack 'Q<', 72623859790382856;; 8 7 6 5 4 3 2 1 [0] Perl> print unpack 'H*', pack 'Q<', 72623859790382856;; 0807060504030201 [0] Perl> print unpack 'h*', pack 'Q<', 72623859790382856;; 8070605040302010 [0] Perl> print unpack 'H*', pack 'Q>', 72623859790382856;; 0102030405060708 [0] Perl> print unpack 'h*', pack 'Q>', 72623859790382856;; 1020304050607080 [0] Perl> print unpack 'b*', pack 'Q>', 72623859790382856;; 10000000 01000000 11000000 00100000 10100000 01100000 11100000 0001000 +0 [0] Perl> print unpack 'B*', pack 'Q>', 72623859790382856;; 00000001 00000010 00000011 00000100 00000101 00000110 00000111 0000100 +0 [0] Perl> print unpack 'b*', pack 'Q<', 72623859790382856;; 00010000 11100000 01100000 10100000 00100000 11000000 01000000 1000000 +0 [0] Perl> print unpack 'B*', pack 'Q<', 72623859790382856;; 00001000 00000111 00000110 00000101 00000100 00000011 00000010 0000000 +1

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

In reply to Re: Is the documentation for Perl 5.20 'pack' correct? by BrowserUk
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.