Acme-Magic8Ball

 view release on metacpan or  search on metacpan

lib/Acme/Magic8Ball.pm  view on Meta::CPAN

54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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



( run in 0.593 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )