#!/usr/bin/perl -w
#######################
# jims2.pl
#
# Shorter version of jims_piglatin
# Seems to mostly work, but does something
# funny on test.txt.  I don't understand
# where the funny business is coming from.
#
#  input:  This is some text.  Yes it is.
#  output: Isthay isway omesay exttay.  E0c0 itway isway.
#
#  input: Yes it is.
#         This is some text.
#  outpu: Esyay itway isway.
#         I0c0 isway omesay exttay.
#
# Jim Mahoney, Oct 29 2003
#######################
use strict;

my $input = join('',<STDIN>);
my @words = split(/\b/,$input);

foreach my $word (@words){
  # leading aeiou vowel
  $word =~ s/^([aeiouAEIOU].*)$/$1way/;
  # not leading aeiou
  $word =~ s/^([^aeiouAEIOU][^aeiouyAEIOUY]*)([aeiouyAEIOUY])(.*)$/$2$3$1ay/g;
  # fix capitalization
  $word =~ s/^(^.*([A-Z]).*)$/\u\L$1/;
  #$word =~ s/.+ $//;
  # And send it on to the output.
  print $word;
}

