最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Perl中的多行字符串

Perl crifan 3940浏览 0评论

【问题】

Perl中,想要写一个多行的字符串。

【解决过程】

1.参考:

perl使用多行string的语法

但是结果试了各种写法:

#!/usr/bin/perl

=File decalaration
Function:
【已解决】Perl中的多行字符串
【已解决】Perl中的多行字符串
Author: Crifan Li Version: 2012-12-24 Contact: admin at crifan dot com =cut use strict; use warnings; $origHtml = <<HTML; <h1>h1 content</h1> <div> div test <div> inside level 1 div </div> </div> HTML; print("origHtml=", $origHtml);

都还是不行。

2.参考了:

Perl-02—字符串

写成:

#!/usr/bin/perl

=File decalaration
Function:
【已解决】Perl中的多行字符串
【已解决】Perl中的多行字符串
Author: Crifan Li Version: 2012-12-24 Contact: admin at crifan dot com =cut use strict; use warnings; $origHtml = <<EOF; <h1>h1 content</h1> <div> div test <div> inside level 1 div </div> </div> EOF print("origHtml=", $origHtml);

结果还是出错:

D:\tmp\tmp_dev_root\perl\remove_html_tag>remove_html_tag.pl

Global symbol "$origHtml" requires explicit package name at D:\tmp\tmp_dev_root\perl\remove_html_tag\remove_html_tag.pl line 16.

Global symbol "$origHtml" requires explicit package name at D:\tmp\tmp_dev_root\perl\remove_html_tag\remove_html_tag.pl line 27.

Execution of D:\tmp\tmp_dev_root\perl\remove_html_tag\remove_html_tag.pl aborted due to compilation errors.

3.后来参考:

Perl Here-Doc Tutorial

还是出错,但是把use strict; 去掉,就可以了:

#!/usr/bin/perl -w

=File decalaration
Function:
【已解决】Perl中的多行字符串
【已解决】Perl中的多行字符串
Author: Crifan Li Version: 2012-12-24 Contact: admin at crifan dot com =cut use warnings; $origHtml = <<END; <h1>h1 content</h1> <div> div test <div> inside level 1 div </div> </div> END print("origHtml=", $origHtml);

输出为:

D:\tmp\tmp_dev_root\perl\remove_html_tag>remove_html_tag.pl

origHtml=<h1>h1 content</h1>

<div>

    div test

    <div>

        inside level 1 div

    </div>

</div>

 

【总结】

还是之前就遇到的,加了strict,就出错了:

【已解决】Perl运行出错:Global symbol xxx requires explicit package name at,Execution of xxx aborted due to compilation errors

所以,其实早就可以了。。。。

转载请注明:在路上 » 【已解决】Perl中的多行字符串

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
95 queries in 0.179 seconds, using 23.18MB memory