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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |