The basic mechanism is simple. For each couple of words, you maintain a list of possible successive words. For example, in the text suggested by me:
this is an interesting text because this is what could be a more interesting text for us
you have the following:
this is => an, what (note: "this is" occurs two times) is an => interesting an interesting => text interesting text => because, for text because => this because this => is ("this is" has already been included above) is what => could ...
When generating a text, given the pair of "last written words", you go into your table and select one of the successors; in most cases (at least in the example) you are forced to a get the single word in the list, but in others you can choose from more alternatives (2 in our case, in particular for the couples "this is" and "interesting text").

If you want to apply this mechanism to the letters, you can "simply" substitute "letter" to "word" in the program. This means hacking on the split in the foreach while taking into proper account newlines in the text (in the program, the newline is considered a "terminator", see $NONWORD). The implementation is left as an exercise, as it would not fit in the border of this reply :)

Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf

Don't fool yourself.

In reply to Re^5: How do I use this Markov generator? by polettix
in thread How do I use this Markov generator? by Philmac

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.