Perl 笔记 

 ●Perl没有Boolean类型他利用如下几条规则:

  ●如果值是数字,0是false;其余为真

  ●如果值为字符串,则空串(‘’)为false;其余为假

  ●如果值的类型即不是数字也不是字符串,则将其转为数字或字符后再利用上述规则。

所有的undef为false;所有的引用为true

“0”等同0  唯一非空但是但值为0的串

chomp($test=<STDIN>);

defined(undef)  false

defined(其余) true

  1. #! /usr/bin/perl
  2. @rocks=qw(ta ds td sa);
  3. print “I have,scalar @rocks ,”rocks\n”;

scalar 强制转换为标量,若不加scalar 则会输出(ta ds td sa),而不是我们期望的4

相关文章:

  • 2021-08-16
  • 2022-01-25
  • 2021-09-24
  • 2022-02-08
  • 2021-10-24
  • 2021-08-11
  • 2021-08-21
  • 2021-10-19
猜你喜欢
  • 2021-12-04
  • 2021-07-10
  • 2022-12-23
相关资源
相似解决方案