最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Perl crifan 5181浏览 0评论

【问题】

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

【解决过程】

1.参考:

perl使用多行string的语法

但是结果试了各种写法:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
 
=File decalaration
Function:
【已解决】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—字符串

写成:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/perl
 
=File decalaration
Function:
【已解决】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; 去掉,就可以了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl -w
 
=File decalaration
Function:
【已解决】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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
85 queries in 0.537 seconds, using 21.98MB memory