Since GrandFather wrote the object oriented code above for me, I am more than willing to show how I would write it in functions. I let my eyes glaze over on the overdrive bit, so I don't have a functional way to do that (if there is a way, that is).
Let's start with the module:
packack Random::Things;
use strict;
use warnings;
use base 'Exporter';
our @EXPORT_OK = qw(RandDayPart RandLight RandWeather RandTense);
sub RandDayPart {
my @randdaypart = qw(morning evening afternoon night);
return $randdaypart[rand @randdaypart];
}
sub RandLight {
my @randlight = qw(bright dark gloomy dazzling);
return $randlight[rand @randlight];
}
sub RandWeather {
my @randweather = qw(stormy windy rainy calm);
return $randweather[rand @randweather];
}
sub RandTense {
my @randtense = ('was', 'is', 'will be');
return $randtense[rand @randtense];
}
1;
Now the script:
use strict;
use warnings;
use Random::Things qw(RandDayPart RandLight RandWeather RandTense);
my $random_day_part = RandDayPart;
my $random_light = RandLight;
my $random_weather = RandWeather;
my $random_tense = RandTense;
print "It $random_tense a $random_light and $random_weather $random_da
+y_part."
It may not be nice and have things like inheritance that the OO version has, but it will do the same thing in a crunch.
Have a cookie and a very nice day!
Lady Aleena
|