【问题】
Perl中,想要写一个多行的字符串。
【解决过程】
1.参考:
但是结果试了各种写法:
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.参考了:
写成:
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 27. Execution of D:\tmp\tmp_dev_root\perl\remove_html_tag\remove_html_tag.pl aborted due to compilation errors. |
3.后来参考:
还是出错,但是把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 <div> div test <div> </div> </div> |
【总结】
还是之前就遇到的,加了strict,就出错了:
所以,其实早就可以了。。。。
转载请注明:在路上 » 【已解决】Perl中的多行字符串