Perl中的“此处”文档
您可以非常舒适地存储或打印多行文本。即使您可以在“此处”文档中使用变量。下面是一个简单的语法,请仔细检查<<和标识符之间是否没有空格。
标识符可以是一个简单的字词,也可以是一些带引号的文本,例如下面我们使用的EOF。如果用引号引起来,则使用的引号类型将决定此处文档中文本的处理方式,就像常规引号一样。未加引号的标识符的作用类似于双引号。
示例
#!/usr/bin/perl $a = 10; $var = <<"EOF"; This is the syntax for here document and it will continue until it encounters a EOF in the first line. This is case of double quote so variable value will be interpolated. For example value of a = $a EOF print "$var\n"; $var = <<'EOF'; This is case of single quote so variable value will be interpolated. For example value of a = $a EOF print "$var\n";
输出结果
这将产生以下结果-
This is the syntax for here document and it will continue until it encounters a EOF in the first line. This is case of double quote so variable value will be interpolated. For example value of a = 10 This is case of single quote so variable value will be interpolated. For example value of a = $a
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短