Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Pig Latin

by clintp (Curate)
on Mar 13, 2001 at 07:28 UTC ( [id://64054]=CUFP: print w/replies, xml ) Need Help??

Pig latin function, written as a small demo for s/// operators. Doesn't work for things like contractions, but hey, life isn't perfect.
{ my $notvowel=qr/[^aeiou_]/i; sub igpay_atinlay { local $_=shift; s[(\w+)] { local $_=$1; s/^($notvowel+)(.*)/$2$1ay/ or s/$/yay/; $_; }ge; $_; } }

Replies are listed 'Best First'.
Re: Pig Latin
by danger (Priest) on Mar 13, 2001 at 12:13 UTC

    For other versions see this node of the same title. Also, there is a module that implements pig latin (there is a module for practically everything ... practical or not :-):

    #!/usr/bin/perl -w use strict; use Text::Bastardize; $_ = "Hey don't it work fine"; my $latin = Text::Bastardize->new(); $latin->charge($_); print $latin->pig(),"\n";

    That module performs other useful transformations like; rot13, censor, and k3wlt0k as well.

Re: Pig Latin
by Adam (Vicar) on Mar 13, 2001 at 11:35 UTC
    Nice. Here is my attempt:
    s/([^aeiou_]+|)(\w*)(\s?)/$2&&$2.($1?$1:'y').'ay '/ige

    Beware of bugs in the above code; I have only proved it correct, not tried it.
    -- March 22, 1977, Donald E. Knuth

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found