Perl 是否具有与 Python 的多行字符串等效的功能?
在 Python 中,您可以使用文档字符串获得像这样的多行字符串
foo = """line1
line2
line3"""
Perl 中是否有等效的东西?
In Python you can have a multiline string like this using a docstring
foo = """line1
line2
line3"""
Is there something equivalent in Perl?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
普通引号:
Here-docs 允许您将任何标记定义为带引号的文本块的末尾:
正则表达式样式引号运算符允许您使用几乎任何字符作为分隔符 - 与正则表达式允许您更改分隔符的方式相同。
更新:更正了此处文档标记。
Normal quotes:
Here-docs allow you to define any token as the end of a block of quoted text:
Regex style quote operators let you use pretty much any character as the delimiter--in the same way a regex allows you to change delimiters.
UPDATE: Corrected the here-doc tokens.
Perl 没有重要的语法垂直空格,因此您可以执行
相当于
Perl doesn't have significant syntactical vertical whitespace, so you can just do
which is equivalent to
是的,这里有一个文档。
Yes, a here-doc.
是的,你有 2 个选择:
1.heredocs 请注意,heredocs 中的每个数据都是插值的:
2.qq() 请参阅示例:
Yes you have 2 options :
1.heredocs please note that every data in heredocs are interpolated :
2.qq() see for example :
简单示例
...结果:
参考:http://perlmaven.com/here-documents
Quick example
...Result:
Reference: http://perlmaven.com/here-documents