in reply to Complaints from Warnings about uninitialized var
It makes sense - because it gets to tell you that middle didn't exist. Try:
split will now say that there was a "middle" field, and split it out. It will be empty, and you'll get what you want. Another alternative is, after splitting, just say:( $first, $middle ) = split ' ', "$first ";
Unfortunately, if $middle were 0, you'd be resetting it to blank. So you could do:$middle ||= '';
Woops - that's perl 6 (or perl 5.10, I hear). I meant:$middle //= '';
Same thing as the previous one, except it works now in perl 5.$middle = '' unless defined $middle;
Without this undef-edness, there'd be no way to tell the difference between a field existing and not. Perl is telling you the field simply doesn't exist. You can fake it to make sure the field exists by putting a space there, or you can deal with the lack of field by resetting it to blank when it is returned as undef. Either way, you're being explicit about what you want, so that no one is confused.
|
|---|