in reply to unititialized value warning

"Note that splitting an EXPR that evaluates to the empty string always returns the empty list, regardless of the LIMIT specified."

$rem holds an empty string, so an empty list is assigned to ($middle, $last), setting $middle and $last to undef.

Fix:

use strict; use warnings; use List::Util qw( shuffle ); while (<DATA>) { s/(?<=\w)(\w+)(?=\w)/ join('', shuffle($1=~m{.}sg)) /eg; print; } __DATA__ I couldn't believe that I was actually understanding what I was reading. The phenomenal power of the human mind, according to research at Cambridge University, suggests that it doesn't matter in what order the letters in a word are, as long as the first and last letters are in the right place. The rest can be a total mess, and you can still read it without a problem. This is because the human mind does not read every letter by itself, but the word as a whole. Amazing, huh? Yeah, and I always thought spelling was important! Check apostrophe and punctuation: Jame's, They're, we'll they'd.

By the way, try replacing

shuffle($1=~m{.}sg)
with
sort $1=~m{.}sg
It'll probably be harder to read.

Replies are listed 'Best First'.
Re^2: unititialized value warning
by wrinkles (Pilgrim) on Mar 14, 2010 at 02:33 UTC
    Thanks ikegami, I just needed to check the variables. This fixed it:
    use strict; use warnings; use List::Util 'shuffle'; while (<DATA>) { my @newline = split(/\b/); for my $word (@newline) { my $first = ""; my $rem = ""; my $middle = ""; my $last = ""; ($first, $rem) = split /(?<=\b\w)/, $word if $word; ($middle, $last) = split /(?=(\w'\w+|\w)$)/, $rem if $rem; ((length $middle) == 2) ? $middle = reverse $middle : ($middle = join "", shuffle(split //, $middle)) if $middle; print "$first" if $first; print "$middle" if $middle; print "$last" if $last; } }