我想将以下perl脚本作为oneliner执行:
perl -e 'print "my $var = "Hello "; print $var."World\n";'
以下面的错误消息结束:
Bareword found where operator expected at -e line 1, near ""$var = "Hello"
(Missing operator before Hello?)
String found where operator expected at -e line 1, near "Hello "; print $var.""
(Do you need to predeclare Hello?)
Backslash found where operator expected at -e line 1, near "World\"
String found where operator expected at -e line 1, at end of line
(Missing semicolon on previous line?)
syntax error at -e line 1, near ""$var = "Hello "
Can't find string terminator '"' anywhere before EOF at -e line 1.
然而,以下声明完美无缺:
perl -e 'print "Hello "; print "World\n";'
似乎perl -e不接受变量。这是真的,如果是,为什么?
答案 0 :(得分:5)
您还有一个"
:
perl -e 'print "my $var = "Hello "; print $var."World\n";'
# here __^
删除它。
但它并不清楚你想要什么。