If I understand correctly, the generation loop (while($cyc_count2 <= keycount)) keeps track of the last few words using @feed and uses them to find a new word. The new word should be found using only the last two words, so @feed should only contain two values at any time, not three:
@feed = @keysout[0,1]; ... while($cyc_count2 <= $keysout){ my $w1 = $feed[0]; my $w2 = $feed[1]; #no $nw needed! ...
After this, the intent seems to be to generate a list of possible next words in which each word appears as many times as it follows these two words in the original text. I think this is the main bug, and the loop should read like this:
for my $word ( keys %{ $hash{ $w1 }{ $w2 }{ words } } ){ push @wordsList, ($word) x $hash{ $w1 }{ $w2 }{ words }{ $word }; }
This way, for each word that ever followed these two (according to the hash), that word is added the same number of times it was seen in this context in the original text.
I don't think this will solve all of the problems with this code, but it's closer to what the code was meant to do.
~dewey

In reply to Re: Scoping Problem? - 'Use of uninititiated value...' by dewey
in thread Scoping Problem? - 'Use of uninititiated value...' by chinamox

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.