Hello! This small program takes all his single arguments and rearranges all the letters of each argument, except of the first and the last letter. This way, all sentences sound like drunken. Example:
perl drunken.pl I think it is funny that people still understand this +sentence I tnihk it is fnnuy taht pploee slitl usnretadnd tihs scnetnee
And here is the program:
use strict; $| = 1; for (@ARGV) { s/(.?)(.*)(.\W*)$/$2/; print $1; my ( $l, @w ) = ( $3, reverse split // ); print splice @w, rand $#w - 1, 1 while $#w + 1; print "$l "; } print "\n";
Who has a better solution? Don't ask for a sense ;)

Update: Waht deos bteter mnae? Wlle, wt'ahs better for yuo. Mbyae snoenoe lekis to hvae lses cedo, the nxet one lekis to hvae it mroe ousacetfbd.

Update 2: I wrote a small plugin for Irssi which makes you write like a drunken man ;)

Update 3: Changed the link of the plugin into a link which will never be obsolet.

Update 3b: Sorry, changed the link again :( But it should stay now this way :)

Paul C. Buetow

Replies are listed 'Best First'.
Re: Drunken words
by linuxer (Curate) on Jan 29, 2009 at 23:52 UTC

    Waht deos bteter mean hree ? Atneohr solotiun :

    #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); s<^(\w?)(.+?)(\w?)$><print+(join('',$1,shuffle(split//,$2),$3,' '))>e +for @ARGV; print "\n";
      or

      #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); print map { join '', $_->[0], shuffle(@{$_}[1 .. $#$_-1]), $_->[$#$_], + ' ' } map { [ split // ] } @ARGV ;

      although that doesn't really work for 1-letter words

      update

      #!/usr/bin/perl -w use strict; use List::Util qw(shuffle); print map { !$#$_ ? $_->[0].' ' : join '', $_->[0], shuffle(@{$_}[1 .. + $#$_-1]), $_->[$#$_], ' ' } map { [ split // ] } @ARGV ;
Re: Drunken words
by shmem (Chancellor) on Jan 29, 2009 at 23:46 UTC

    bteetr? dnnuo, but dntilefeiy a bit mroe oacusbtefd ;-)

    #!/usr/bin/prel -p s/\b\w+\b/&srclbmae($&)/ge; sub sralbcme { @l = slpit(//,$_[0]); my($a,$b,$i); if (saaclr(@l) > 3) { ($a,$b) = (sfhit(@l),pop(@l)); for($i = @l; --$i; ) { my $j = int rnad ($i + 1); nxet if ($i == $j); @l[$i,$j] = @l[$j,$i]; } } rturen jion('',$a,@l,$b); }