funny game

R

robin

this is some basic stuff, but I think some of you might have fun with
it,
--


#!/perl
use strict;
my @compresponses=('Yes.', ' No.', 'Maybe.', 'Nothing doing.', 'You
might be
crazy to ask that.', 'You are so cool.', 'The magic 8 box likes you',
'Cool!', 'Hmmm.',
'2$#@(&*#&*(*&#$$&(*', 'No way in heck.',, 'Good luck.', 'I like what
you\'re doing with yourself', 'This game sucks.', 'Better luck next
time.',
'Try again.', 'Maybe so.', 'Forever.', 'Difficult to tell.', 'You
really
crack me up.',
'Good, but no cigar.', 'Have a cold beer.', 'Having fun?', 'Good
thinking.',
'Whatever.','Are you implying I am fat?','Go and put the kettle on.','I
want
you to think about what you just asked.','Fourty Two.','It will all end
in
tears.',
'A long time ago in a galaxy far far away...','I\'m late for a very
important date.','That\'s hard to say - I\'ll have to get back to
you.','Such things are not for me to decide.','I have a
dream!','Vanity,
Vanity, All is vanity!',
'Are you always this tenecious?','I could tell you, but then I\'d have
to
kill you.','What do I look like - a fortune teller!?');

my $in;
my $answer;
while ()
{
srand;
print "Ask the magic 8 ball a question: (\"q\" to quit)\n";
$in = <STDIN>;
chomp ($in);
print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n" and
exit
if $in eq "q";
next if ! $in or $in =~ /^\s*$/;
$answer = $compresponses[int rand @compresponses];
print "ANSWER: $answer\n\n";
sleep 2;
}
 
P

Paul Lalli

robin said:
this is some basic stuff, but I think some of you might have fun with
it,
--


#!/perl
use strict;

After $deity knows how many years, you *still* refuse to use warnings?!
my @compresponses=('Yes.', ' No.', 'Maybe.', 'Nothing doing.', 'You
might be
crazy to ask that.', 'You are so cool.', 'The magic 8 box likes you',
'Cool!', 'Hmmm.',
'2$#@(&*#&*(*&#$$&(*', 'No way in heck.',, 'Good luck.', 'I like what
you\'re doing with yourself', 'This game sucks.', 'Better luck next
time.',
'Try again.', 'Maybe so.', 'Forever.', 'Difficult to tell.', 'You
really
crack me up.',
'Good, but no cigar.', 'Have a cold beer.', 'Having fun?', 'Good
thinking.',
'Whatever.','Are you implying I am fat?','Go and put the kettle on.','I
want
you to think about what you just asked.','Fourty Two.','It will all end
in
tears.',
'A long time ago in a galaxy far far away...','I\'m late for a very
important date.','That\'s hard to say - I\'ll have to get back to
you.','Such things are not for me to decide.','I have a
dream!','Vanity,
Vanity, All is vanity!',
'Are you always this tenecious?','I could tell you, but then I\'d have
to
kill you.','What do I look like - a fortune teller!?');

Gaahhhhh! What do you have against legible code? And *why* are you
mixing logic with data?!
my $in;
my $answer;

Neither of these are used outside the following block. They should be
declared in the smallest scope possible.

Personal preference - that looks yucky. Like you forgot something.
while (1) at least makes it explicit you're writing an infinite loop.

Wholly unnecessary. Please read:
perldoc -f rand
print "Ask the magic 8 ball a question: (\"q\" to quit)\n";
$in = <STDIN>;
chomp ($in);

chomp (my $in = said:
print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n" and
exit
if $in eq "q";

but not if $in is 'Q'?
next if ! $in or $in =~ /^\s*$/;

So that the question can't consist of a single 0? Because an empty
string is already taken care of by the regexp.
$answer = $compresponses[int rand @compresponses];
print "ANSWER: $answer\n\n";
sleep 2;
}

IMHO, this looks rather cleaner:
#!/usr/bin/perl
use strict;
use warnings;
chomp (my @compresponses=<DATA>);

my $in;
do {
print qq/Ask the magic 8 ball a question: ("q" to quit)\n/;
chomp ($in = <STDIN>);
unless ($in =~ /^\s*$/ or lc $in eq 'q'){
my $answer = $compresponses[int rand @compresponses];
print "ANSWER: $answer\n\n";
sleep 2;
}
} until lc $in eq 'q';

print "\n\n--Mail me at webmaster\@infusedlight.net!--\n\n";

__DATA__
Yes.
No.
Maybe.
Nothing doing.
You might be crazy to ask that.
You are so cool.
The magic 8 box likes you
Cool!
Hmmm.
2$#@(&*#&*(*&#$$&(*
No way in heck.
Good luck.
I like what you're doing with yourself
This game sucks.
Better luck next time.
Try again.
<etc...>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top