衫裤跑路 2010-01-11 23:16 采纳率: 50%
浏览 182
已采纳

在 Perl 中,检查字符串是否为空的正确方法是什么?

I've just been using this code to check if a string is empty:

if ($str == "")
{
  // ...
}

And also the same with the not equals operator...

if ($str != "")
{
  // ...
}

This seems to work (I think), but I'm not sure it's the correct way, or if there are any unforeseen drawbacks. Something just doesn't feel right about it.

转载于:https://stackoverflow.com/questions/2045644/what-is-the-proper-way-to-check-if-a-string-is-empty-in-perl

  • 写回答

5条回答 默认 最新

  • 喵-见缝插针 2010-01-11 23:20
    关注

    For string comparisons in Perl, use eq or ne:

    if ($str eq "")
    {
      // ...
    }
    

    The == and != operators are numeric comparison operators. They will attempt to convert both operands to integers before comparing them.

    See the perlop man page for more information.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码