I need a little help with this script. I wrote this small script to count repeating bytes in small files (200kb or less), which it is doing, but its not doing it correctly I do not think.
use strict;
use warnings;
my $count = 0;
my @array;
while ( read( DATA, my $byte, 1 ) ) {
if ( $byte ~~ @array ) {
$count++;
print @array;
undef @array;
}
else {
undef @array;
push @array, $byte;
print @array;
}
}
print $count;
__DATA__
1112223333
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 :)