Not to be a jerk here but this is like the 15th Markov Chains program posted to PM. =) Not that this isn't a good one but we made need to add a line asking if you are posting a text munger that produces semi-random text by breaking up another text into keys and single letter/words. =)

I love these things that mangle text. Just about the first non-work sample program that I wrote in perl was a Markov chain generator. Since this is my 500th post (good grief!) I figured I'd babble again about my favorite text mangling system.

Things to try, change it from a 3|1 chain to a 4|1 or a 4|2 chain. Add a statistical element to the dataset so you can weight the likelyhood of the following letter: chai=>{n=> 5, r=> 3}, hear=>{ " "=>1, t=>3}, Might as well add in requests for what size chain keys to use.

>Ask all the questions then do all the work in one pass. It doesn't make much difference here but it is a good habit to get into if you decide to loop over lines or multiple files in the future. Also killing tabs and newlines and duplicate spaces is nice one shot deal:

my %flag; print "\nReduce white space? >> "; chomp (my $space = <STDIN>); $flag{space}=1 if ($space =~/^y/i); print "\nQuick and dirty strip of HTML tags? >> "; chomp (my $htmlstrip = <STDIN>); $flag{htmlstrip}=1 if ($htmlstrip =~/^y/i); if ($flag{htmlstrip}) { s/<br>/\n/ig; s/<[^>]+>//g; #etc... } s/\s\s+/ /g if $flag{space}; }

I have to say that the reverse trick to use chop is pretty unique. I've not seen it done that way and might just have to Benchmark that vs. other methods. I used:

for (my $i=0; $i<(length -4); $i++) { push @{$strings{substr ($_,$i,4)}},substr($_,$i+4,1); # or # $strings{substr (_,$i,4)}{substr($_,$i+4,1)}++; }

Other Markov Chain posts I found: Markov Chain Program, Travesty -- done properly, on CPAN,

I'm glad I'm not the only evil munger out there. =) =)

--
$you = new YOU;
honk() if $you->love(perl)


In reply to Re: Is it random? by extremely
in thread Is it random? by ColonelPanic

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.