了解奇怪的Perl多行注释机制
编辑:注意新的Perl程序员:这个机制不应该用于多行注释!它具有缺陷降低的可读性.
在这个PerlMonks post on mechanisms to produce multiline comments in Perl年,阿比盖尔提供了这个,这让我很困惑:
<<q=~q>>; This is a multiline comment. q 运行通过-M0 = Deparse给出: " This is a multiline comment.n" =~ //; -e syntax OK 有人可以告诉我发生了什么吗? 解决方法
阿比盖尔的答案部分幽默.实际上没有<< >>运算符(不是在Perl
before 5.22的版本中),但是有一个(不是众所周知的,我猜)操作符.不是二进制移位运算符,而是一元
here-document (heredoc for short).一个简单的形式是:
$long_string = <<EOF; This is a long,multiline string. It ends when EOF appears alone on a line. It will be assigned to the $long_string variable. EOF 实际上,这就是Abigail答案的“多行评论”功能 – 多行字符串文字.其余的是有点混淆的Perl. 在<<<结束字符串文字.你可以使用q作为一个裸字: <<q; This is a multiline comment,or rather a string literal whose value is ignored. q 要了解Abigail的其他代码片段,它有助于将这个文档重写成简单的字符串文字: "This is a multiline comment.n" =~ q>>; 好的,现在q>>是 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |