http://qs321.pair.com?node_id=291720

Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:

I'm guessing most of you have seen this much-forwarded email?
Aoccdrnig to a rscheearch at an Elingsh uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is that frist and lsat ltteer is at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae we do not raed ervey lteter by it slef but the wrod as a wlohe.

It's an interesting phenomenon, but who wants to play golf with the process to put regular text into this strange form of mangled but still readable text?

The first and last letters must be correct, and the rest of the letters must be out of order.

Here's a version I'm totally not proud of but I put it together in a few minutes.

sub mangle { my $input = shift (); my @words = split ('\s', $input); foreach my $item (@words) { my $punctuation = ''; if($item =~ s/(\.|,)$//){ $punctuation = $1; } if (length($item) > 3) { $item =~ m/^(.)(.+?)(.)$/; my $centre = $2; while ($centre eq $2) { my @centre = split ('', $2); shuffle(@centre); $centre = join ('', @centre); } $item = $1 . $centre . $3 . $punctuation; } else { $item .= $punctuation; } } return join (' ', @words); } ### NB: shuffle routine is not my work. sub shuffle { my $i = @_; # length of @_ array while ($i) { my $j = rand $i--; @_[ $i, $j ] = @_[ $j, $i ]; # 0 <= int($j) <= $i } }


($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print