
chengkai
stranger
Oct 17, 2001, 10:11 AM
Views: 20759
|
|
Re: Perl Golf to translate to Pig Latin
|
|
|
As put a little thought with the previous regex, I came out another way to do the same job. This time, it will be more compact and hard to read: So I added comments in each line to make everybody to read it more easily. while (<DATA>) { # we need to use 1 while ( ... ) format; otherwise the regex can apply to all words in a line # 1 while ( /\s*([aeiou]\w+)\s*(?{print $1, 'way '}) # if word start with vowel then add "way" after it | # or \s*[^aeiou](\w+)\s*(?{print $2, 'ay '}) # if the word that is not start with vowel then add "ay" after it /gx # apply the regex global to the sentence ); print "\n"; } ~Mike L.
(This post was edited by chengkai on Oct 17, 2001, 10:07 AM)
|