my $fil = shift; open (FIL, $fil) || die ("can't read $fil: $!"); my $filstr = do { local $/; }; close FIL; my %charhash; $charhash{$_}++ for ( split //, $filstr ); my $ent = entropy(\%charhash, length( $filstr )); printf ("file %s\ncontents entropy = %30.20f\n",$fil,$ent); sub entropy { my ($hashref, $total, $baselog) = @_; $baselog = 0.693147180559945 unless $baselog; # log(2) return undef unless ( ref $hashref and $total > 0 ); my $sum; $sum += $_ * (log($_)/$baselog) for ( map { $_/$total } values %$hashref ); return -$sum; }