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

Re^2: How do unpack templates work

by unlinker (Monk)
on Jul 20, 2012 at 19:06 UTC ( [id://982889]=note: print w/replies, xml ) Need Help??


in reply to Re: How do unpack templates work
in thread How do unpack templates work

Yes - that works! Thanks.

I agree that the efficiency/speed argument is not particularly compelling in this case. But a single unpack (when written correctly ;) ) is way more elegant that a bunch of substr calls

Will wait for a later day to better understand why 'C' does not work

Replies are listed 'Best First'.
Re^3: How do unpack templates work
by BrowserUk (Patriarch) on Jul 20, 2012 at 19:44 UTC
    Will wait for a later day to better understand why 'C' does not work

    Don't wait. Try a few simple tests:

    print unpack 'H*', $uuid;; 767adecd8ed2e11191f4b1907aa0b7e4 print unpack 'a4', $uuid;; vzÌ═ print unpack 'C4', $uuid;; 118 122 222 205

    Look up what the 'C' template does. (Hint: see also ord ).


    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.

    The start of some sanity?

      The first snippet is clear. So is the second, which I verified, extracts the first 4 bytes into a single variable. I do not understand your output in this case 'vzI&#..'

      Your example now makes the C template clear - it works differently in the sense that the number that follows the C is the number of octets to extract rather than number of octets to combine into a single variable.

      I missed this in the docs, if it is mentioned there. Is this behaviour unique to C? Again I could not find it in the docs. If you used the docs to figure this out, I would appreciate a pointer to the section

        I do not understand your output in this case 'vzI&#..'

        The last of the 4 characters, the ═ bit, is just a side effect of pasting console output into PMs code block.

        Somewhere along the line, some characters with the high-bit set (ie. chars greater than 127) get converted into unicode html escape sequences.

        Outside of a code block that looks like this: ═, which is exactly how it appeared on my console prior to C&P.

        Is this behaviour unique to C?

        No, it also applies to 'c' & 'W'.

        As for documentation: for unpack, all it basically says is that it is the reverse of pack. Look at the docs for the latter, and think about the logical reverse.

        But more than any other piece of Perl, the *only* way to understand pack & unpack, is to get yourself a REPL and sit and play.


        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.

        The start of some sanity?

Log In?
Username:
Password:

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

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

    No recent polls found