【发布时间】:2019-11-20 21:30:58
【问题描述】:
我是 Perl 的新手。我想用. 运算符连接一个字符串和一个数字,第一个参数将是一个数字。我可以使用 join、sprintf 并简单地将它们打印为打印数字、字符串。但我用. 运算符试了一下,得到了以下结果:
$foo = "hello".34 # Gives hello.34
$foo = 34."hello" # Gives an error
$foo = 34.34 # Gives 34.34
$foo = 34.34.34 # Gives """
$foo = "hello".34."hello" # Gives an error
我在 Perl 调试器下试过了。
为什么 Perl 不将数字和字符串连接起来,将数字作为第一个参数,反之亦然?为什么 34.34.34 在 Perl 中会给出 """?
【问题讨论】:
-
你确定
"hello".34真的给出了hello.34(带有句号)吗?在命令行(Linux,Ubuntu MATE 20.04 (Focal Fossa))上,perl -le 'print "hello".34 '输出hello34(没有句号)。
标签: perl concatenation