in reply to Fun with words (Golf?)

  1. There's no reason to explicitly skip words less then 4 characters. if it's less then four, shuffling the "middle letters" will either be a shuffle of one, or zero characters.
  2. This doesn't solve the problem exactly as you described (your requirements about comma,period are pretty specific, and don't cover other punctuation), but it's pretty close...
    #!perl -p use List::Util 'shuffle'; $_=~s{(?<=\b\w)(\w+)(?=\w\b)}{join'',shuffle split//,$1}xeg;
    It's by no means a good Golf ... but it's a good starting point.
I'm not sure why i posted it in that format, this makes more sense if we're talking about golf...
perl -MList::Util=shuffle -pe '$_=~s{(?<=\b\w)(\w+)(?=\w\b)}{join"",sh +uffle split//,$1}xeg;'

Replies are listed 'Best First'.
Re^2: Fun with words (Golf?)
by Roy Johnson (Monsignor) on Nov 09, 2005 at 16:01 UTC
    You have more rigor in your regex than is needed.
    perl -MList::Util=shuffle -pe 's:\B\w+\B:join"",shuffle split//,$&:ge'

    Caution: Contents may have been coded under pressure.

      Look Ma, no modules!

      perl -pe's!\B\w+\B!@s=split//,$&;my$s;$s.=splice@s,rand@s,1while@s;$s! +eg'
      Three chars for List::Util is a good trade, I think... :-)

      -sauoq
      "My two cents aren't worth a dime.";
      
        An alternative to split trims two of those chars.
        perl -pe's!\B\w+\B!@s=$&=~/./g;my$s;$s.=splice@s,rand@s,1while@s;$s!eg +'

        Caution: Contents may have been coded under pressure.

      ahh, \B ... I can't remember the last time i had a reason to use that ... nice catch.