Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How do unpack templates work

by BrowserUk (Patriarch)
on Jul 20, 2012 at 18:47 UTC ( [id://982882]=note: print w/replies, xml ) Need Help??


in reply to How do unpack templates work

Try:

my( $bit1, $bit2 ) = unpack 'a4 a*', $uuid;

But, regarding your "more efficient than substr" remarks. For the sake of a single operation like this, you won't notice the difference; even if there actually is any.


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?

Replies are listed 'Best First'.
Re^2: How do unpack templates work
by unlinker (Monk) on Jul 20, 2012 at 19:06 UTC

    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

      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-18 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found