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

But that is a different number :)

https://metacpan.org/pod/perlfunc#pack says

The integer formats s, S, i, I, l, L, j, and J ... For example, a 4-byte integer 0x12345678 (305419896 decimal) would be +ordered natively (arranged in and handled by the CPU registers) into +bytes as 0x12 0x34 0x56 0x78 # big-endian 0x78 0x56 0x34 0x12 # little-endian

So I type

$ perl -V:byteorder byteorder='1234'; $ perl -e"print 0x12345678 " 305419896 $ perl -e"print unpack q{H*}, pack q{N*}, 0x12345678 " 12345678 $ perl -e"print unpack q{H*}, pack q{N*}, 305419896 " 12345678 $ perl -e"print sprintf q{%x}, 305419896 " 12345678
Which seems to agree with above and  N  An unsigned long (32-bit) in "network" (big-endian) order.

N packs 305419896 correctly as big-endian, and my machine is big endian (as sprintf shows)

Replies are listed 'Best First'.
Re^2: Is the documentation for Perl 5.20 'pack' correct?
by ikegami (Patriarch) on Jul 07, 2015 at 00:34 UTC
    The docs don't say the output of perl -V:byteorder has any relationship to 0x12345678. It simply (and correctly) says it's 1234 or 12345678 on LE systems.

      The docs don't say the output of perl -V:byteorder has any relationship to 0x12345678. It simply (and correctly) says it's 1234 or 12345678 on LE systems.

      You're a great communicator ikegami

        Thanks! I've always found that adding runnable examples and diagrams help a lot.