Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
And here it is:

from the first Programming Perl (back when it was still pink)

#!/usr/bin/perl # Usage travesty [files] # First analyse the input. while(<>) { # handle article headers and ">>>" quotes. next if /^\./; next if /^From / .. /^$/; next if /^Path: / .. /^$/; s/^\W+//; # Do each word. push(@ary,split(' ')); while ($#ary > 1) { $a = $p; $p = $n; $w = shift(@ary); $n = $num{$w}; if ($n eq '') { push(@word,$w); $n = pack('S',$#word); $num{$w} = $n; } $lookup{$a . $p} .= $n; } } # Now spew out the words, based on the frequencies. If there # is more than one possibility to choose from choose one # randomly. for (;;) { $n = $lookup{$a . $b}; ($foo,$n) = each(lookup) if $n eq ''; # A bootstrap. $n = substr($n,int(rand(length($n))) & 0177776,2); $a = $p; $p = $n; ($w) = unpack('S',$n); $w = $word[$w]; # See if word fits on line; $col += length($w) +1; if ($col >= 65) { $col = 0; print "\n"; } else { print ' '; } print $w; # Paragraph every 10 sentences or so. if ($w =~ /\.$/) { if (rand() < .1) { print "\n"; $col = 80; } } }
p.s. These little gems are the reason I keep that old pink book around.

In reply to Re: (tye)Re: Transcramble - Random text generator by blakem
in thread Transcramble - Random text generator by OeufMayo

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (6)
    As of 2020-10-22 22:53 GMT
    Find Nodes?
      Voting Booth?
      My favourite web site is:

      Results (230 votes). Check out past polls.