免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2250 | 回复: 3
打印 上一主题 下一主题

here document 相关资料 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-09-04 21:44 |只看该作者 |倒序浏览
###链接http://perldoc.perl.org/perlop.html
<<EOF
A line-oriented form of quoting is based on the shell "here-document" syntax. Following a << you specify a string to terminate the quoted material, and all lines following the current line down to the terminating string are the value of the item. The terminating string may be either an identifier (a word), or some quoted text. If quoted, the type of quotes you use determines the treatment of the text, just as in regular quoting. An unquoted identifier works like double quotes. There must be no space between the << and the identifier, unless the identifier is quoted. (If you put a space it will be treated as a null identifier, which is valid, and matches the first empty line.) The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.

       print <<EOF;
    The price is $Price.
    EOF       print << "EOF"; # same as above
    The price is $Price.
    EOF       print << `EOC`; # execute commands
    echo hi there
    echo lo there
    EOC       print <<"foo", <<"bar"; # you can stack them
    I said foo.
    foo
    I said bar.
    bar       myfunc(<< "THIS", 23, <<'THAT');
    Here's a line
    or two.
    THIS
    and here's another.
    THATJust don't forget that you have to put a semicolon on the end to finish the statement, as Perl doesn't know you're not going to try to do this:

       print <<ABC
    179231
    ABC
       + 20;If you want your here-docs to be indented with the rest of the code, you'll need to remove leading whitespace from each line manually:

    ($quote = <<'FINIS') =~ s/^\s+//gm;
       The Road goes ever on and on,
       down from the door where it began.
    FINISIf you use a here-doc within a delimited construct, such as in s///eg, the quoted material must come on the lines following the final delimiter. So instead of

    s/this/<<E . 'that'
        the other
        E
          . 'more '/eg;you have to write

    s/this/<<E . 'that'
          . 'more '/eg;
    the other
    E

[ 本帖最后由 zhangkeyijian 于 2007-9-5 13:31 编辑 ]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2007-09-05 08:57 |只看该作者
不明白你有什么问题。

论坛徽章:
0
3 [报告]
发表于 2007-09-05 13:04 |只看该作者
here document的语法错了:
print <<END_OF_DATA

...................

END_OF_DATA

论坛徽章:
0
4 [报告]
发表于 2007-09-05 13:27 |只看该作者
对不起,打扰大家了。
问题得到解决,由于自己没有仔细检查。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP