What is the proper way to check if a string is empty in Perl?

后端 未结 6 1890
日久生厌
日久生厌 2020-12-25 09:18

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

6条回答
  •  不思量自难忘°
    2020-12-25 09:54

    To check for an empty string you could also do something as follows

    if (!defined $val || $val eq '')
    {
        # empty
    }
    

提交回复
热议问题