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:
At first I wrote this as a sub called pick:$trans[int(rand($#trans + 1))]
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.
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |