— |
#!/usr/bin/perl
getopts "b:e=" , \ my %o ;
my $tmp = <> if $o { '=' } ;
my %strcnt ;
my $allcnt = 0 ;
while ( <> ) {
chomp ;
$strcnt { $_ } ++ ;
$allcnt ++ ;
}
my $entropy = 0 ;
for ( values %strcnt ) {
my $p = $_ / $allcnt ;
$entropy -= $p * log $p ;
}
my @out ;
unshift @out , exp $entropy if $o {e} ;
$o {b} //= 2 ;
unshift @out , $entropy / log $o {b} ;
print join "\t" , @out ;
print "\n" ;
BEGIN {
$Getopt::Std::STANDARD_HELP_VERSION = 1 ;
our $VERSION = 0.21 ;
}
sub HELP_MESSAGE {
$ARGV [1] //= '' ;
open my $FH , '<' , $0 ;
while (< $FH >){
s/\$0/ $Script /g ;
print $_ if s/^=head1// .. s/^=cut// and $ARGV [1] =~ /^o(p(t(i(o(ns?)?)?)?)?)?$/i ? m/^\s+\-/ : 1;
}
close $FH ;
exit 0 ;
}
|