off the record, heretofore, the officer found that in the theater of war, one hath need of a weatherproof theory of games #### 8 7 7 6 6< th> 6< t> 5< o> 5 5< the> 4 4 4 4 4< of> #### #!/usr/bin/perl # Write a substring analysis of an input text, like Moby's sample. # All whitespace is considered a single space. use strict; use Getopt::Long; my %Substrings; my $Minimum = 2; my $Shortest = 2; my $Longest = 5; my $Limit = 500; GetOptions('minimum=i' => \$Minimum, 'shortest=i' => \$Shortest, 'longest=i' => \$Longest, 'limit=i' => \$Limit); exit(main(@ARGV)); sub main { my $input; do { local $/ = undef; $input = <>; }; $input =~ s/\n/ /gs; $input =~ s/\s+/ /gs; for my $span ($Shortest .. $Longest) { for my $pos (0 .. length($input)-$span) { $Substrings{ substr($input, $pos, $span) }++; } } my $count = 0; foreach (grep { not $Limit or $count++ < $Limit } grep { $Substrings{$_} >= $Minimum } sort { $Substrings{$b} <=> $Substrings{$a} } keys %Substrings) { print $Substrings{$_}, '<', $_, '>', "\n"; } }