blib/lib/Shannon/Entropy.pm

filter: Statementstmt 100% 23 / 23 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 100% 30 / 30 CC 3 SCAR 5.6
CC
3
Cov
100%
entropy
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.8
↑ Summary
1 package Shannon::Entropy;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Import::Export;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base qw/Import::Export/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION = '1.101111';
12  
13 2 our %EX = (
14 entropy => [qw/all/]
15 );
16  
17 sub entropy {
18 5 ▶ my ($entropy, $len, $p, %t) = (0, length($_[0]));
Subroutine entropy: called CC=3 SCAR=11.0
Pod documented
19 5 $t{$_}++ foreach split '', $_[0];
20 5 foreach (values %t) {
21 57 $p = $_/$len;
22 57 $entropy -= $p * log $p;
23 }
24 5 return $entropy / log 2;
25 }
26  
27 2 1;
28  
29 __END__
↑ Summary