in reply to Re^7: pack/unpack binary editing
in thread pack/unpack binary editing

I will give this a shot. What I really need to do with the sync pattern is find every occurance and extract it along with the following 476 bytes discarding everything after the 476th byte up to the next sync.

Replies are listed 'Best First'.
Re^9: pack/unpack binary editing
by BrowserUk (Patriarch) on Feb 10, 2005 at 14:25 UTC

    In that case, the code in Re^5: pack/unpack binary editing should be easily adaptable to your purpose. You'll need to understand how it works, but the code from the previous post can be combined with it to do everything, including the syncing in a single pass.


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.
      Thanks for all your help. Regarding the code you posted. You'll have to fogive my ignorance. Could you break down your substitution line. I don't really understand what it's doing. I ran the code. Not sure how much faster it is 'cause I stopped it. My results were wrong. The substitution isn't quit right. I need to be able to look at every 2 bits and then determine if they are a 11 or a 00 then replace and move on to the next 2 bits.

        Okay. Re-reading your code, I think that you only want to replace the paired bits on even bit boundaries?

        Substitute this for the other regex.

        $bits =~ s[(..)][ ## Look at every pair of bits $1 eq '00' ## If they are 00 ? '11' ## replace them 11 : $1 eq '11' ## If they are 11 ? '00' ## replace them with 00 : $1 ## else leave them alone ]ge;

        That will slow it down a bit, but it will still run quicker than splitting the string into and array etc.


        Examine what is said, not who speaks.
        Silence betokens consent.
        Love the truth but pardon error.