Whew! I started to refactor this but ran into some things I couldn't translate. So I thought I would point out what I found and let you do the work. (Who knows, it might be homework.)

First off, you use the following block over and over. It screams for a subroutine:

$trans[int(rand($#trans + 1))]
At first I wrote this as a sub called pick:
sub pick { my $aref = shift; return $aref->[int(rand(scalar(@$aref)))]; }

Second, rather than having an array for each language element type, I would put this in a hash of arrays (HOA):

my %parts = ( det => [qw{the a ninety}], #determiner pro => [qw{it I ya theirs}], # pronoun properNoun => [qw{Alpesh Ann China Beijing}], # proper noun ...

That way you could access individual items with:

$parts{adj}->[1]

And combine this with the pick function I mentioned up above. To pick one word out of any part:

pick($parts{adj});

Next a couple of observations. In createNP I ran across a problem. You're using a global variable $randnum to hold a random number:

sub createNP{ my(@adjp); while ((my$counter = 0) < 100) { $randnum = int(rand(5)+1); if ($randnum == 1) { $randnum = int(rand(2)+1); if ($randnum == 1)

After looking at it, it looks right, but it would be better if you used a local variable to hold the random value that is used within a local scope. Also the problem with the while loop that was mentioned earlier.

sub createNP{ my(@adjp); my $counter = 0; while ($counter < 100) { my $outerRN = int(rand(5)+1); if ($outerRN == 1) { my $innerRN = int(rand(2)+1); if ($innerRN == 1)

Finally, I noticed that you are using an array to accumulate results:

$np[$counter] = $pluralNoun[int(rand($#pluralNoun + 1))];

This can be done without an index by using the push function.

push(@np , $pluralNoun[int(rand($#pluralNoun + 1))])

All I've got time for now. HIH.


"Look, Shiny Things!" is not a better business strategy than compatibility and reuse.


In reply to Re: hanging at odd place, can still input but see nothing on screen (newbie) by osunderdog
in thread hanging at odd place, can still input but see nothing on screen (newbie) by etherC

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.