zoukankan      html  css  js  c++  java
  • 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

    【责任编辑:云霞 TEL:(010)68476606】
    回书目   上一节   下一
  • 相关阅读:
    中移动ipv6-老毛子固件获取ipv6设置
    win7-win10 禁用IPV6临时地址
    辅助调用函数【call,apply,bind】
    Unraid修改docker镜像地址&默认启动
    docker基本入门知识-小白向
    [不止于代码]Unraid基本使用速记
    Dockerfile文件说明
    Git之pull,fetch差别
    代码片段添加智能提示,打造一款人见人爱的ORM框架
    新定义三层,指挥官模式
  • 原文地址:https://www.cnblogs.com/chip/p/4215923.html
Copyright © 2011-2022 走看看