use strict; use lib qw(./); use Huffman qw(:All); use Data::Dumper; my @word = ( 'http://www.perlmonks.org/index.pl?parent=43933;node_id=3333', 'http://www.coasthome.com/things.html', 'http://validator.w3.org/check', 'http://www.google.com/search?q=emdash+html&sourceid=mozilla-search&start=&start=&ie=utf-8&oe=utF-8&client=firefox&rls=org.mozilla:en-US:unofficial', 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', ); # build tree my @paths = build_encodings(join('', @word)); my $path_hash = build_encodings_hash(join('', @word)); my $tree = build_tree(join('', @word)); use Data::Dumper; print Dumper $path_hash; for my $string (qw ( http://lawyers.findlaw.com/lawyer/firm/Estate-Planning/Fort-Bragg/North-Carolina http://www.seacrestproperties.com/ http://www.fortbragg.com/businesses_all.lasso ) ) { my $encoded_str; my $str; foreach my $item (split('', $string)) { if (my $ele = $path_hash->{$item}) { $encoded_str .= $ele->{ENCODING}; } else { die "No encoding for $item\n"; } } print "String: $string\n"; print "Encoded:\n$encoded_str\n"; # converting this to a bit vector is left as a exercise. $encoded_str = $encoded_str; my $decoded = decode_str($encoded_str,@paths); print "Decoded:\n".$decoded."\n"; print "Stats: \n"; print "Original chars: ".length($string)."\n"; print "Original size (in bits): ".(8*length($string))."\n"; print "Encoded size (in bits): ".length($encoded_str)."\n"; print "Size reduction: %".((1-(length($encoded_str)/(8*length($string))))*100)."\n"; }