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.


In reply to unititialized value warning by wrinkles

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.