in reply to Byte repetition check

In this code, it should match "1" 2 times, "2" 2 times, and "3" 3 times, which would be a total of 7 repeating bytes. The script only counts 5 repeating bytes. What am I missing? I know its something simple probably. Any help would be appreciated :)

You are smart matching a byte against an array.

  1. The array is initially empty, so you take the else branch and (re)empty it before pushing the character into it, and then print its content.
  2. On the second pass: the array will contain one character; so you increment your count; print the array -- which will still only have one character in it; and then empty it.
  3. The array is now empty (again), so goto step 1.

So, step through the ten iterations of your loop on paper, recording the changes to @array and $count, and it will be very clear to you where you are going wrong.

(You also appear to have a newline character as the first line of your file, which probably isn't meant to be there?)


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.

Replies are listed 'Best First'.
Re^2: Byte repetition check
by james28909 (Deacon) on Dec 11, 2014 at 04:27 UTC
    Nope, the first newline isnt suppose to be there. Thanks for pointing that out.