【问题标题】:Meaning of <=> (less than, equal, greater than) in Perl?Perl中<=>(小于,等于,大于)的含义?
【发布时间】:2011-10-21 22:06:22
【问题描述】:

this answer,我看到了&lt;=&gt;的语法;这是什么意思?这似乎是基于上下文的某种比较,但我只能收集到这些。部分上下文:

sub rev_by_date { $b->[9] <=> $a->[9] }
my @sorted_files = sort rev_by_date @files;

【问题讨论】:

  • Perl 运算符记录在 perldoc perlop perldoc.perl.org/perlop.html
  • 谢谢,我不知道那个 perlop 页面!
  • 您的版本的文档与 Perl 一起安装:$ perldoc perltoc 您应该至少阅读整个集合一次。
  • 也称为“星舰操作员”

标签: perl comparison operators comparison-operators


【解决方案1】:

来自Perldoc

二进制“”返回 -1、0 或 1,具体取决于左侧是否 参数在数值上小于、等于或大于右边 争论。如果您的平台支持将 NaN(非数字)作为数字 值,将它们与“”一起使用会返回 undef。 NaN 不是“"、"=" 任何东西(甚至是 NaN),所以这 5 个返回 false。南!= NaN 返回 true,NaN != 其他任何东西也是如此。如果您的平台 不支持 NaN,那么 NaN 只是一个数值为 0 的字符串。

【讨论】:

  • 谢谢,该链接也很有帮助!
猜你喜欢
  • 1970-01-01
  • 2011-01-25
  • 2012-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-02
  • 2018-11-23
  • 1970-01-01
相关资源
最近更新 更多