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