Hi fellow monks,
What is my code doing that warrants a warning, and how do I fix it? Thanks. Abridged warnings:
Use of uninitialized value in length at ./jumble.pl line 34, <DATA> li
+ne 1.
Use of uninitialized value in split at ./jumble.pl line 34, <DATA> lin
+e 1.
Use of uninitialized value in concatenation (.) or string at ./jumble.
+pl line 36, <DATA> line 1.
Use of uninitialized value in split at ./jumble.pl line 33, <DATA> lin
+e 1.
The offending code
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;
($middle, $last) = split /(?=(\w'\w+|\w)$)/, $rem;
((length $middle) == 2) ? $middle = reverse $middle :
($middle = join "", shuffle(split //, $middle));
print "$first$middle$last";
}
}
__END__
I couldn't believe that I was actually understanding what I was readin
+g.
The phenomenal power of the human mind, according to research at Cambr
+idge University,
suggests that it doesn't matter in what order the letters in a word ar
+e, as long as
the first and last letters are in the right place. The rest can be a t
+otal 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 apostrope and punctuation: Jame's, They're, we'll they'd.
And here's the output, with warnings off:
I cdolun't beievle taht I was aalulcty uedsnadnnitrg waht I was rdaenig.
The peeaonhmnl peowr of the hmuan mnid, adcircnog to rerecash at Cibmdarge Uteirsvniy,
ssugetgs taht it dosen't mettar in waht odrer the lterets in a wrod are, as lnog as
the fisrt and lsat ltteres are in the rghit pcale. The rset can be a toatl mses,
and you can siltl raed it woihtut a pboerlm. Tihs is bceusae the hmuan mnid deos
not raed eervy lteetr by iseltf, but the wrod as a wlhoe. Ainzamg, huh? Yaeh,
and I ayawls tguhhot splileng was intpaormt!
Cchek asoptorpe and puttiunoacn: Jmae's, Tehy're, we'll tehy'd.