Perl的here文档机制是从UNIX shell中的here文档机制派生而来的。

和在shell中一样,Perl中的here文档也是面向行的引用表单,要求提供<<运算符,其后跟随一个初始的终止字符串。

<<之后可以不出现空格。

如果终止字符串没有加上引号或双引号,则允许执行变量表达式。

如果终止字符串上加了单引号,则不执行变量表达式。用户应当把文本的第一行内容插入到第一个和最后一个终止字符串之间。

最后一个终止字符串必须位于该行上,且周围不允许出现空白字符。

与UNIX shell不同的是,Perl不允许在here文档中执行命令替换。

另一方面,如果将终止字符串包含在反引号中的话,Perl也允许在here文档中执行该命令。

#!/bin/perl $price=100;

1 print <<EOF; # No quotes around terminator EOF are same # as double quotes

2 The price of $price is right. # Variables are expanded

3 EOF

4 print <<'FINIS';

5 The price of $price is right. # The variable is not expanded # if terminator is enclosed in single quotes

6 FINIS

7 print << x 4; # Prints the line 4 times

8 Christmas is coming! # Blank line is necessary here as terminating string

9 print <<'END'; # If terminator is in backquotes, # will execute UNIX commands

10 echo hi there

11 echo -n "The time is "

12 date

13 END

(Output)

2 The price of 100 is right.

5 The price of $price is right.

8 Christmas is coming!

Christmas is coming!

Christmas is coming!

Christmas is coming!

10 hi there The time is Fri Nov 3 17:03:46 PST 2000

【责任编辑:云霞 TEL:(010)68476606】
回书目   上一节   下一

最新文章

  1. Visual Studio Emulator for Android 初体验
  2. 纯CSS 图片演示
  3. Android 配置问题
  4. AIX 环境下ODM库同步
  5. (转)提高mysql千万级大数据SQL查询优化30条经验(Mysql索引优化注意)
  6. [内核]Takslet和Workqueue的应用场景
  7. UVA11806-Cheerleaders(容斥原理+二进制)
  8. Spring中依赖注入的使用和配置
  9. Teamwork——Week4 团队项目之NABC
  10. Objective-C ,ios,iphone开发基础:使用第三方库FMDB连接sqlite3 数据库,实现简单的登录
  11. bzoj 3105: [cqoi2013]新Nim游戏 异或高消 &amp;&amp; 拟阵
  12. 成为IT经理必备的十大软技能
  13. Android开源项目发现---ActionBar篇(持续更新)
  14. ValidateBox( 验证框) 组件
  15. java学习之Java中JDK,JRE和JVM之间的关系(转载)
  16. 经典合集 - WP8.1数据源
  17. 华为Java机试题
  18. VMware与CentOS的安装与Linux简单指令
  19. Select2异步搜索数据
  20. creator.d.ts 的错误

热门文章

  1. PostgreSQL - 模糊查询
  2. 在Ubuntu14.04 64位上安装Clion
  3. IM 通讯录
  4. JSP | 基础 | 中文字符的传递
  5. 去掉UItalbeview横线
  6. [題解](DP)CF713C_Sonya and Problem Wihtout a Legend
  7. C#基础之析构函数
  8. Hungary Algorithm国外板子
  9. ZooKeeper理论知识
  10. ListBox,CheckBoxList,DropDownList,RadioButtonList的常见数据绑定