#!/usr/local/bin/perl # report the entropy of this distribution # one line per prob. lengths optional $i = 0 ; $c = 0 ; $h = 0 ; while( <> ) { ( $x , $l , $rest ) = split ; $c += $x ; $h -= $x * log ( $x) ; $i ++ ; $L += $l * $x ; } $h /= log ( 2.0 ) ; printf "I=%2d, c=%5f, H=%5f, L=%5f\n" , $i , $c , $h , $L ;