]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/piglatin.pl
iglatinpay
[infobot.git] / src / Modules / piglatin.pl
1 # turns english text into piglatin
2 # Copyright (c) 2005 Tim Riker <Tim@Rikers.org>
3
4 use strict;
5 use warnings;
6
7 package piglatin;
8
9 sub piglatin
10 {
11   my ($text) = @_;
12   my $piglatin;
13   my $suffix = 'ay';
14
15   # FIXME: does not handle:
16   #  punctuation and hyphens
17   #  y as vowel "style" -> "ylestay"
18   #  contractions
19   for my $word (split /\s+/, $text) {
20     my $pigword;
21     if ($word =~ /^(qu)(.*)/ ) {
22       $pigword = "$2$1$suffix";
23     } elsif ($word =~ /^(Qu)(.)(.*)/ ) {
24       $pigword = uc($2) . $3 . lc($1) . $suffix;
25     } elsif ($word =~ /^([bcdfghjklmnpqrstvwxyz]+)(.*)/ ) {
26       $pigword = "$2$1$suffix";
27     } elsif ($word =~ /^([BCDFGHJKLMNPQRSTVWXYZ])([bcdfghjklmnpqrstvwxyz]*)([aeiouy])(.*)/ ) {
28       $pigword = uc($3) . $4 . lc($1) . $2 . $suffix;
29     } else {
30       $pigword = $word . 'w' . $suffix;
31     }
32     $piglatin .= " $pigword";
33   }
34   &::performStrictReply($piglatin||'failed');
35 }
36
37 1;