This modified version avoids proper nouns and applies some meter to the verses by counting (half-)syllables.
#!/usr/bin/perl #ode to a random number v0.2 open my $dict, "</usr/share/dict/words" or open my $dict, "</usr/share/lib/dict/words" ; my @words = <$dict>; my $count = 70*rand(); { use integer; $count /= 1; } my $syllables = 0; for ( 'a', 'e', 'i', 'o', 'u' ) { $vowel{ $_ } = 1; } for ( 0..$count ) { my $ptr; my $thissyll; do { $ptr = rand() * $#words; $thissyll = Syllables( $words[$ptr] ); } until ( $words[$ptr] eq lc( $words[$ptr] ) and ((20-$syllables-$thissyll) >= 0 )); $syllables += $thissyll; chomp $words[$ptr]; unless( $_ ) { $words[ $ptr ] =~ /^(.)(.*)$/; my $b = uc( $1 ); $words[$ptr ] = $b . $2; } if ( $_ < $count ) { print $words[$ptr]; if ( $syllables >= 20 ) { print ";\n"; $syllables = 0; } else { print ' '; } } else { print $words[$ptr] . ".\n"; } } sub Syllables { my $word = shift; chomp $word; my $lv = 0; my $tv; my $syll = 0; for my $letter( split '', $word ) { $tv = $vowel{ $letter }; ( $tv == $lv ) or $syll++; $lv = $tv; } return $syll; }
First output:
Policeman nereid spokesman trendy; fragmentary magnetite enunciate; dyspeptic lean recombinant decile myrtle; afterlife disdain derange redneck; devious attentive condemnatory nymph 2nd sou; astigmatism shine zagging sage auk; incentive tattle woodrow deposit; boolean stagnant setback cull objet dust; elysian stuck temper freethink octile my yea; trauma endogamous cohesive hay; applejack ramp squalid beatitude a; byline novitiate noun rawhide guile; cutset pig sundown puff stablemen max; meteoritic sword dose epiphyseal vie; ceremony.

-M

Free your mind


In reply to Re: Ode to a random number by Moron
in thread Ode to a random number by Moron

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.