Acme-Magic8Ball

 view release on metacpan or  search on metacpan

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



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