Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

(Ovid) Perl Golf (cont...)

by Ovid (Cardinal)
on Jul 24, 2000 at 03:10 UTC ( #24020=note: print w/ replies, xml ) Need Help??


in reply to RE: (3)Perl Golf (Pig Latin dialect)
in thread Pig Latin

Okay, let me see if I have this right:

  • Generally, we should have a 1-to-1 mapping (flea and leaf should be distict).
  • Words beginning with "th" should have this combination moved to the end. I also assumed that words starting with "wh", "ch" and the like would exibit this behavior.
  • I also assumed that "qu" would be moved to the end (though I didn't try anything fancy with words like "qaid" and "qintar".)
I think the following will do the trick:
my $test = "Wherefore art thou, Ovid, you moronic chowderheaded shell +of a ghost? Give me my fleas and leaf."; $test =~ s/\b(qu|[cgpstw]h|[^\W0-9_aeiou])?([a-z]+)/$1?"$2$1ay":"$2way +"/ieg; print $test; Output (split on two lines for legibility): ereforeWhay artway outhay, Ovidway, ouyay oronicmay owderheadedchay el +lshay ofway away ostghay? iveGay emay ymay leasfay andway eaflay.
This one is rather tricky because it relies on how Perl's regex engine works. Because Perl uses the traditional NFA engine, it takes the first successful match in the alternation and runs with it. Therefore, I need to test for possibilities like the "th" in "thistle" before I test for the "t" in "testy". Otherwise, the regex engine would grab the first "t" in words beginning with "th" and try to complete the match.

Cheers,
Ovid


Comment on (Ovid) Perl Golf (cont...)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24020]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-11-26 10:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (167 votes), past polls