CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Fun With Perl: Perl Golf: Re: Perl Golf to translate to Pig Latin: Edit Log



chengkai
stranger

Oct 17, 2001, 10:11 AM


Views: 34551
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)


This post has not been edited


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives