Created
March 22, 2016 17:31
-
-
Save anonymous/90311d86df5d12b7c3fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# histogram of bytes in a file. | |
use v6; | |
#my $fh = slurp :bin; | |
my @c; | |
my $i = 0; | |
loop ($i=255; $i>=0; $i--) { | |
@c[$i]=0; | |
} | |
my $count=0; | |
while defined $_ = $*IN.getc { | |
$count++; | |
$i = ord($_); | |
if ($i>255) { $i=255; } | |
@c[$i]++; | |
} | |
$i=0; | |
for @c { | |
print sprintf("%c %7d ",$i,$_); | |
$i++; | |
if ($i%8 == 0) { say; } | |
} | |
say "\ntotal: ", $count; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment