in reply to why is this code bad under -w option?
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 ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: why is this code bad under use strict?
by Grygonos (Chaplain) on Jul 28, 2003 at 14:03 UTC |