加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl并不抱怨??丢失分号

发布时间:2020-12-15 21:20:03 所属栏目:大数据 来源:网络整理
导读:我刚刚在Ubuntu上发现,Perl并没有抱怨最后的分号。检查以下代码: #!/usr/bin/perluse warnings;use strict;my @array = (1,2,3,4);foreach (@array){ print $_."n"}print "no,this cant be true" 请注意分号“;”从打印声明中缺少。仍然代码运行正常。 OU
我刚刚在Ubuntu上发现,Perl并没有抱怨最后的分号。检查以下代码:
#!/usr/bin/perl
use warnings;
use strict;

my @array = (1,2,3,4);

foreach (@array)
{
    print $_."n"
}

print "no,this cant be true"

请注意分号“;”从打印声明中缺少。仍然代码运行正常。

OUTPUT:

1
2
3
4
no,this cant be true

如果我打印后分号,它仍然可以工作。所以这是令我困惑的。

你能帮我理解我在这里丢失了什么,还是有一些我忽略的明显的Perl意识形态?

解决方法

从 perldoc perlsyn:

Every simple statement must be terminated with a semicolon,unless it is the final statement in a block,in which case the semicolon is optional.

您的打印声明是块中的最后一个语句。

不推荐使用分号。如果稍后再扩展块太容易忘了添加它。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读