2016-02-24 15:41:19 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use Getopt::Long;
|
|
|
|
use Pod::Usage;
|
|
|
|
use autodie;
|
|
|
|
|
|
|
|
my $encoding;
|
|
|
|
|
|
|
|
GetOptions('encoding=s', \$encoding) or pod2usage();
|
|
|
|
|
|
|
|
my %hist;
|
|
|
|
if (@ARGV) {
|
|
|
|
readfile($_) for @ARGV;
|
|
|
|
} else {
|
|
|
|
readfile();
|
|
|
|
}
|
|
|
|
|
2018-09-13 19:02:40 +02:00
|
|
|
my $total = 0;
|
|
|
|
$total += $_ for values %hist;
|
|
|
|
|
2016-02-24 15:41:19 +01:00
|
|
|
binmode STDOUT, ":encoding(UTF-8)";
|
|
|
|
for (sort keys %hist) {
|
|
|
|
my $cp = ord;
|
2018-09-13 19:02:40 +02:00
|
|
|
printf("%x %d %o %s\t%8d %f\n",
|
|
|
|
$cp, $cp, $cp, /\p{Graph}/ ? $_ : ".", $hist{$_}, $hist{$_} / $total);
|
2016-02-24 15:41:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
sub readfile {
|
|
|
|
my ($filename) = @_;
|
|
|
|
my $fh;
|
|
|
|
if (defined $filename) {
|
|
|
|
open $fh, "<", $filename;
|
|
|
|
} else {
|
|
|
|
$fh = \*STDIN;
|
|
|
|
|
|
|
|
}
|
|
|
|
binmode $fh, ":encoding($encoding)";
|
|
|
|
while (<$fh>) {
|
|
|
|
for my $c (split(//)) {
|
|
|
|
$hist{$c}++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|