# determine char entropy from file. by wufnik. my $fil = shift; open (FIL, $fil) || die ("no filfor entropy calc, $!"); my $filstr = do { local $/; }; close FIL; my @chars = split //, $filstr; my (%charhash, $charstot); map { $charhash{$_}++; $charstot++ } @chars; my @values = map { $_ / $charstot } values %charhash; my $ent = entropy(\@values); printf ("file %s\ncontents entropy = %20.15f\n",$fil,$ent); sub entropy{ my ($listr, $baselog) = @_; $baselog = 0.693147180559945 unless $baselog; # log(2) return undef unless ref $listr; my $sum; my @nums = @$listr; map { $sum += $_ * (log($_)/$baselog) } @nums; return -$sum; }