in reply to unpacking variable length bit fields

This is a little simpler.

map oct( "0b$_" ), unpack 'A3A2A2A1A4A2A1A1A2A2A1A1A2', unpack 'B*', +$x;;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: unpacking variable length bit fields
by Skeeve (Parson) on Oct 24, 2006 at 12:18 UTC
    Thanks! Not as elegant as I hoped but it has the big advantage: It works correct!

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

      I know what you mean. You want to be able to replace all the As with Bs and skip the first step, but of course each B starts a new byte. Maybe there could be something like unpack 'B{3,2,2,1}B{4,2,1,1}B{2,2,1,1,2}', $x?

      I've also had occassion to want to extract bit-ranges that cross byte boundaries and that gets real messy. Maybe an enhanced vec that allows non-powers-of-two sizes. That shouldn't be so hard to write.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.