Combining our various suggestions and in the interests of TIMTOWTDI I offer the following:
use warnings; use strict; my %moods = ( good => ["nfs", "nfsII", "With the PerlMonks", "Morrowind", "TES C +onstructor Set"], bad => ["RedFactionII", "CCG", "RavenShield", "AGG"], ); my $mood; while (1) { print "How has your day been?\n"; $mood = <STDIN>; chomp $mood; $mood = lc $mood; last if exists $moods{$mood}; } my $gamesRef = $moods{$mood}; my $randgame = $gamesRef->[rand @$gamesRef]; print "You should play: $randgame\n";
which gives the hash an improved name and better facilitates a solution to homework problem 2.
Panda should note the use of the if as a statement modifier in last if ... and the alternate syntax used for dereferencing the array ref ($gamesRef->). Note too that the {} brackets are not required for @$gamesRef.
In reply to Re^2: Decisiveness for Gamers
by GrandFather
in thread Decisiveness for Gamers
by Panda
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |