in reply to Re: Not quite an OO tutorial
in thread Not quite an OO tutorial
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Not quite an OO tutorial
by james2vegas (Chaplain) on Feb 24, 2011 at 06:37 UTC | |
by Lady_Aleena (Priest) on Feb 24, 2011 at 07:20 UTC | |
by RedElk (Hermit) on Feb 24, 2011 at 18:44 UTC | |
by Anonymous Monk on Feb 24, 2011 at 09:08 UTC | |
by Lady_Aleena (Priest) on Feb 26, 2011 at 20:01 UTC |
In Section
Meditations