I\'ve just been using this code to check if a string is empty:
if ($str == \"\")
{
// ...
}
And also the same with the not equals operato
Due to the way that strings are stored in Perl, getting the length of a string is optimized.
if (length $str)
is a good way of checking that a string is non-empty.
If you're in a situation where you haven't already guarded against undef
, then the catch-all for "non-empty" that won't warn is if (defined $str and length $str)
.