use strict; use Statistics::Frequency; use FileHandle; use Data::Dumper; sub simplifyText { my $txt = shift; $txt =~ s/\s+/ /g; $txt =~ tr/A-Z/a-z/; $txt =~ tr[.(),/:][]d; return $txt; } my $f1 = Statistics::Frequency->new; my $fn = "/net/fox/vol02/tallman/notes/dynamac"; my $fh = new FileHandle("<" . $fn); defined $fh or die "Cannot open $fn: $!\n"; local $/ = undef; my $text = <$fh>; $text = simplifyText($text); print "text *$text*\n"; my @txt = split //,$text; my @txt_nospaces = grep { $_ ne ' ' } @txt; $f1->add_data(\@txt_nospaces); my $f2 = Statistics::Frequency->new; my $last = undef; my $letter; my @pairs = (); foreach $letter (@txt) { if ($letter eq ' ') { $last = undef; next; } push @pairs,($last . $letter) if defined $last; $last = $letter; } $f2->add_data(\@pairs); my %freq = $f1->frequencies; print Data::Dumper->Dump([\%freq],["*freq"]); my %freq2 = $f2->frequencies; print Data::Dumper->Dump([\%freq2],["*freq2"]);