in reply to a question about making a word frequency matrix

This may get you started. Note that it does not find the top 100 words, it counts all words over 4 characters long.

use strict; use warnings; use Text::ExtractWords qw(words_count); my %words; my @paraStats; local $/ = '-100'; while (<DATA>) { chomp; s/[\n\r]/ /g; my %paraWordFreq; words_count(\%paraWordFreq, $_, minwordlen => 4); push @paraStats, {%paraWordFreq}; map {$words{$_} = 0} keys %paraWordFreq; } my $col = 0; print ' ' x 17; for (sort keys %words) { next if 4 > length $_; $words{$_} = ($col += 1 + length $_); print "$_ "; } my $paraNum = 1; for (@paraStats) { printf "\nParagraph %5d: ", $paraNum++; my $col = 0; my %paraWords = %$_; for (sort keys %paraWords) { next if 4 > length $_; printf "%*d ", $words{$_} - $col - 1, $paraWords{$_}; $col = $words{$_}; } } __DATA__ The first row is top 100 frequent words (in the text file). Numbers in + each cell shows the frequency of the word in the data. The data is one text file + (.txt) with more than 100000 words. -100 Each "paragraph" is delimited by "-100". I need a matrix which shows t +he frequency of each word in each paragraph. I thought it is words-by-wor +ds matrix, but it's wrong. It's words-by-paragraph matrix. Thank you very much! P +eace of the world.

Prints (note that the lines are long:

100000 cell data delimited each file first frequency +frequent it's matrix more much need numbers paragraph peace shows tex +t than thank thought very which with word words words-by-paragraph wo +rds-by-words world wrong Paragraph 1: 1 1 2 1 2 1 1 + 1 1 1 1 +2 1 1 1 2 Paragraph 2: 1 1 + 1 Paragraph 3: 2 1 + 2 3 1 1 1 1 1 + 1 1 1 1 1 1 + 1 1 1

DWIM is Perl's answer to Gödel