Use of uninitialized value in string eq at sourcefile, line 32.

'Use of uninitialized value' means that there's a variable that has no value (is undef) when that's not appropriate. Without -w, undef is usually converted to '' as necessary, but with -w, it complains.

Where is the complaint? Line 32 of your source code. Go there and see what you see. It might be an approximation, given the loose syntax of statements that take up multiple lines.

What operator is complaining? 'string eq'. One side of the 'eq' is undef. $block_type eq 'KB' You should wager it's the side that is a variable, since the constant is never undef.

What should you do about it? Go back and look at where you last modified the variable in question. What if $1 is undefined? What should you do?

$block_size =~ m{([a-zA-Z]{2}$)}; $block_type = $1 || '';

Your pattern captures any two adjacent letters at the end of the string. If there are not two adjacent letters at the end of the string, then $1 is undef. The above uses $1 if defined, or an empty string '' otherwise. You might decide to fall back on 'KB' as a default instead of an empty (invalid) block type.

--
[ e d @ h a l l e y . c c ]


In reply to Re: why is this code bad under -w? by halley
in thread why is this code bad under -w option? by Grygonos

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.