Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Txet Maglning Glof, Ayobndy?

by Abigail-II (Bishop)
on Sep 16, 2003 at 08:30 UTC ( [id://291761]=note: print w/replies, xml ) Need Help??


in reply to Txet Maglning Glof, Ayobndy?

A lot of the solutions reverse the inner part of the word. For many words, this scrambles the word, but it fails on words where the middle part is a palindrome, like motor. I believe that the following substitution doesn't suffer from such a problem, it will mangle all mangable words, and it won't loop on unmangable words:
s/(\w)(\w)(\w+)(\w)/$1$3$2$4/;

Abigail

Replies are listed 'Best First'.
Re: Re: Txet Maglning Glof, Ayobndy?
by halley (Prior) on Sep 16, 2003 at 14:12 UTC
    As pointed out, this misses apostrophes. I don't mind missing those. But we can chop even more.
    perl -pe 's:\B(\w)(\w+)\B:$2$1:g' # ------------------------ # 12345678 1 2345678 2 234

    --
    [ e d @ h a l l e y . c c ]

      It misses out on apostrophes because the original question didn't deal with them either. It wasn't specified how those should be handled. Note that it's fairly trivial to replace \w with [\w'], as long as you don't use \B or \b.

      Abigail

      Maybe I am doing something wrong, but I tried your one-liner and it does not work:
      perl -pe 's:\B(\w)(\w+)\B:$2$1:g' According to a research at an English university, it doesn't matter in + what orde r According to a research at an English university, it doesn't matter in + what orde r
      It just reprinted the exact same line I typed in.

      Celebrate Intellectual Diversity

        If you're on Windows, use double-quotes on the command line. If you're on any Un*x variety, including cshell and bash on Solaris and Linux, use the single-quotes as given.

        Every command shell differs in what needs escaping, and what is seen as one argument, or two arguments. However, many people playing golf seem to prefer the Un*x varieties. Maybe it's because Un*x has inspired golf since its inception: cp instead of copy; mv instead of move; ln instead of link; etc.

        Know your command shell.

        --
        [ e d @ h a l l e y . c c ]

        Shells often play tricks on us all -> `perldoc perlrun' -> On some systems, you may have to change single-quotes to double ones
        C:>perl -pe s:\B(\w)(\w+)\B:$2$1:g According to a research at an English university, it doesn't matter in + what order Acordincg to a rsearceh at an Eglisnh uiversitny, it deson't mttear in + waht oderr One two three four, NodeReaper is gonna score! One two trehe fuor, NdeReapeor is gnnoa sorce! ^Z

        MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
        I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
        ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Re: Txet Maglning Glof, Ayobndy?
by Anonymous Monk on Sep 16, 2003 at 08:39 UTC
    hmmm, can't won't isn't don't ?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-26 06:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found