#!/usr/bin/env perl use utf8; ############################################################################### # This program reads bytes from STDIN and then computes a frequency table. # # Copyright © 2020 Richard Lesh. All rights reserved. ############################################################################### use Utils; use strict; use warnings; MAIN: { binmode(STDOUT, ":utf8"); binmode(STDERR, ":utf8"); binmode(STDIN, ":utf8"); my $total_count = 0; my $count_table = [(undef) x 256]; for (my $x = 0; $x <= 255; ++$x) { $count_table->[$x] = 0; } binmode(STDIN); my $c; while (defined($c = Utils::getbyte(*STDIN))) { ++$count_table->[$c]; ++$total_count; } print "Dec\tHex\tCount\tFreq\n"; for (my $x = 0; $x <= 255; ++$x) { if ($count_table->[$x] > 0) { my $FREQ = $count_table->[$x] / $total_count; print Utils::messageFormat("\{0:d\}\t\{0:02x\}\t\{1:d\}\t\{2:.4f\}", $x, $count_table->[$x], $FREQ), "\n"; } } }