Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/90311d86df5d12b7c3fd to your computer and use it in GitHub Desktop.
Save anonymous/90311d86df5d12b7c3fd to your computer and use it in GitHub Desktop.
# 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