Hi Panda,
Very nice job! In addition to the things that GrandFather mentioned I'd like to encourage you to think about using hashes and references (see perlref and perldsc), because you are duplicating the core of the code for each option - you use essentially the same code for 'good' as you do for 'bad', the only thing that changes is the name of the array. By using the technique shown below you can add other moods without having to copy and paste the code block for each new mood.
use warnings; use strict; my %games = ( good => [ "nfs", "nfsII", "With the PerlMonks", "Morrowind", "TES Constructor Set" ], bad => [ "RedFactionII", "CCG", "RavenShield", "AGG" +], ); # another way to loop my $mood = ''; while( ! exists $games{$mood} ) { print "How has your day been?\n"; $mood = <STDIN>; chomp $mood; $mood = lc $mood; } my $game_aref = $games{$mood}; my $randgame = ${ $game_aref }[ rand @{ $game_aref } ]; print "You should play: $randgame\n";
To add a new mood, all you have to do is add it to the hash:
Feel free to ask if you have any questions about the code.my %games = ( good => [ "nfs", "nfsII", "With the PerlMonks", "Morrowind", "TES Constructor Set" ], bad => [ "RedFactionII", "CCG", "RavenShield", "AGG" +], fantastic => [ "With the PerlMonks" ], );
Now for some homework:
I hope this helps, and that it gives you some things to think about and play with. Have fun! :-)
In reply to Re: Decisiveness for Gamers
by bobf
in thread Decisiveness for Gamers
by Panda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |