]> git.donarmstrong.com Git - infobot.git/blobdiff - src/Modules/piglatin.pl
* Merge changes from prposed changes
[infobot.git] / src / Modules / piglatin.pl
index 27830e0dcb5deb9f91342edb4c40067b2db1370d..7e1bcd42e039f3c599b945d352f4fb14b2bc606b 100644 (file)
@@ -13,11 +13,15 @@ sub piglatin
   my $suffix = 'ay';
 
   # FIXME: does not handle:
-  #  punctuation and hyphens
-  #  y as vowel "style" -> "ylestay"
+  #  non-trailing punctuation and hyphens
+  #  y as vowel 'style' -> 'ylestay'
   #  contractions
   for my $word (split /\s+/, $text) {
-    my $pigword;
+    my ($pigword, $postfix);
+    #($word,$postfix) = $word =~ s/^([a-z]*)([,.!\?;:'"])?$//i;
+    if ($word =~ s/([,.!\?;:'"])$//i) {
+      $postfix = $1;
+    }
     if ($word =~ /^(qu)(.*)/ ) {
       $pigword = "$2$1$suffix";
     } elsif ($word =~ /^(Qu)(.)(.*)/ ) {
@@ -29,9 +33,12 @@ sub piglatin
     } else {
       $pigword = $word . 'w' . $suffix;
     }
-    $piglatin .= " $pigword";
+    $piglatin .= ' ' if $piglatin;
+    $piglatin .= $pigword . $postfix;
   }
   &::performStrictReply($piglatin||'failed');
 }
 
 1;
+
+# vim:ts=4:sw=4:expandtab:tw=80