Acme-Magic8Ball
view release on metacpan or search on metacpan
Allow passing own answers
Allow making answers consistent (thanks Mark A. Smith)
Wed Oct 15 2008 23:30 - v1.2 @ rather than $#
Fix bug http://rt.cpan.org/Ticket/Display.html?id=40080
from Zoffix Znet - not choosing from all the answers
Thu Jan 13 2005 13:58 - v1.1 Silly bug
Must reset DATA handle
Thu Jan 13 2005 13:23 - v1.0 Initial release
Even though it's very silly
lib/Acme/Magic8Ball.pm view on Meta::CPAN
If you don't pass in an array of answers it will use the traditional ones.
=cut
sub ask {
my $question = shift || return "You must ask a question!";
my @answers = @_;
unless (@answers) {
my $pos = tell DATA;
@answers = map { chomp; $_ } <DATA>;
seek DATA, $pos,0;
}
return $answers[rand @answers] unless $CONSISTENT;
my $hashcode = 0;
$hashcode += ord($_) foreach split(//, $question);
return $answers[$hashcode % scalar(@answers) - 1];
}
=head1 AUTHOR
lib/Acme/Magic8Ball.pm view on Meta::CPAN
The 8 Ball FAQ - http://8ball.ofb.net/faq.html
Mattel (who own the 8 Ball) - http://www.mattel.com
=cut
__DATA__
Signs point to yes.
Yes.
Reply hazy, try again.
Without a doubt.
My sources say no.
As I see it, yes.
You may rely on it.
Concentrate and ask again.
Outlook not so good.
It is decidedly so.
( run in 0.803 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )