#!/usr/bin/perl
open my $dict, ";
my $count = 100*rand();
{ use integer; $count /= 1; }
for ( 0..$count ) {
my $ptr = rand() * $#words;
chomp $words[$ptr];
unless( $_ ) {
$words[ $ptr ] =~ /^(.)(.*)$/;
my $b = uc( $1 );
$words[$ptr ] = $b . $2;
}
if ( $_ < $count ) {
print $words[$ptr] . ' ';
}
else {
print $words[$ptr] . ".\n";
}
}
-M
Free your mind
"dying Asilomar straggle suggestively overtakes relive" – cool.
Anyway, random generated ode? I have one of those too: Re: Ode for getprotobyname.
-M
Free your mind
#!/usr/bin/perl
#ode to a random number v0.2
open my $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
CountZero
"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
perlmonks.org content © perlmonks.org and ambrus, CountZero, dwildesnl, Moron
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03