Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found