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

In reply to Re: a question about making a word frequency matrix by GrandFather
in thread a question about making a word frequency matrix by peacekorea

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.