Yes, it will assign the blank string. But the warning is for mentioning an undefined value in the if test itself. It is only a warning. You should try to quite the warning with something like this:
if ( defined $value_a and $value_a =~ /personal/ ) {...
And one minor modification that no one seems to have mentioned yet would be to "factor" out the assignment with the ternary C<?:> operator, which also makes for a more concise but still fairly readable (actually, more readable IMHO) syntax like thus:
$value_a = defined $value_a && $value_a =~ /personal/ ? 'checked' : ''
+;
Since in both cases $value_a would appear quite a number of times, and that makes the whole thing less readable, well at least for me, I feel like using a pronoun instead, that is a C<for> loop's aliasing property. In the second case this "trick" can easily be cast in the form of a statement modifier:
$_ = defined && /personal/ ? 'checked' : '' for $value_a;
But readability is such a subjective matter and this use so controversial that I won't certainly insist on it. |