在Python中,你可以使用docstring
获得这样的多行字符串foo = """line1
line2
line3"""
Perl中是否有相同的东西?
答案 0 :(得分:37)
正常报价:
# Non-interpolative
my $f = 'line1
line2
line3
';
# Interpolative
my $g = "line1
line2
line3
";
Here-docs允许您将任何标记定义为引用文本块的结尾:
# Non-interpolative
my $h = <<'END_TXT';
line1
line2
line3
END_TXT
# Interpolative
my $h = <<"END_TXT";
line1
line2
line3
END_TXT
正则表达式样式引用运算符允许您使用几乎任何字符作为分隔符 - 就像正则表达式允许您更改分隔符一样。
# Non-interpolative
my $i = q/line1
line2
line3
/;
# Interpolative
my $i = qq{line1
line2
line3
};
更新:更正了here-doc令牌。
答案 1 :(得分:32)
Perl没有重要的语法垂直空格,所以你可以做到
$foo = "line1
line2
line3
";
相当于
$foo = "line1\nline2\nline3\n";
答案 2 :(得分:15)
是的,是here-doc。
$heredoc = <<END;
Some multiline
text and stuff
END
答案 3 :(得分:0)
是的,你有两个选择:
1.heredocs请注意,heredocs中的每个数据都是内插的:
my $ data =&lt;
您的数据
END
2.qq()参见例如:
print qq( HTML
$ your text
BODY
HTML );
答案 4 :(得分:0)
快速示例
#!/usr/bin/perl
use strict;
use warnings;
my $name = 'Foo';
my $message = <<'END_MESSAGE';
Dear $name,
this is a message I plan to send to you.
regards
the Perl Maven
END_MESSAGE
print $message;
<强> ...结果: 强>
Dear $name,
this is a message I plan to send to you.
regards
the Perl Maven
参考:rowCount