Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

RE: (3)Perl Golf (Pig Latin dialect)

by ybiC (Prior)
on Jul 24, 2000 at 02:38 UTC ( [id://24018]=note: print w/replies, xml ) Need Help??


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

"does not produce a 1-to-1 mapping"

As children, my brothers and I used a dialect of Pig Latin that did provide 1-to-1 mapping.   If I remember right, flea translated to lea-fay, yet leaf translated to eaf-lay.

Off the top of my head, TH was the only consonant combination that didn't break like that.   How might such discernment be added to y'all's way-clever regexes?
    cheers,
    ybiC

Replies are listed 'Best First'.
RE: RE: (3)Perl Golf (Pig Latin dialect + clever regexes)
by japhy (Canon) on Jul 24, 2000 at 02:54 UTC
    Pig Latin words are not supposed to begin with consonants. flea becomes ea-flay and leaf becomes eaf-lay. If you use hyphens, you can create that distinction. If you don't want to use a visible character, though, insert a NUL. Oh, and since when does about become aboutway? I never heard of the 'insert a w' rule.
    s/\b(qu|[^\W0-9_aeiou]+)?(\w+)/$1?"$2\0$1ay":"$2\0ay"/egi;
    The preceeding code allows you to decode the string. While it does effect length(), a simple (?) work-around would be:
    package PigLatin; use overload ( q{""} => sub { (my $str = ${ $_[0] }) =~ tr/\0//d; return $str; }, fallback => 1, ); sub to { my ($class,$word) = @_; $word =~ s/\b(qu|[^\W0-9_aeiou]+)?(\w+)/$1?"$2\0$1ay":"$2\0ay"/egi; bless \$word, $class; } sub from { my $word = substr ${ $_[-1] }, 0, -2; # $word has the \0 in it return join "", reverse split /\0/, $word; } 1;
    This module would be used as so:
    use PigLatin; $plain = "Practical Extraction and Report Language"; $funny = to PigLatin $plain; $reg = from PigLatin $funny;
    length($funny) would be 50, but length($$funny) is 55, due to the 5 added NULs.

    $_="goto+F.print+chop;\n=yhpaj";F1:eval
(Ovid) Perl Golf (cont...)
by Ovid (Cardinal) on Jul 24, 2000 at 03:10 UTC
    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

Log In?
Username:
Password:

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

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

    No recent polls found