问题描述
尝试在命令窗口中运行一个简单的 Perl 脚本,但出现错误:
Trying to run a simple Perl script in a command window and am getting error:
字符串终止符'";-e line 1 处 EOF 之前的任何位置
代码
perl -e 'print "Hello World";'
我做错了什么?
推荐答案
哪个平台?如果是 Windows 和 CMD.EXE,那么各种事情都可能出错.在类 Unix 平台上,这应该可以正常工作.末尾没有换行符,因此您的提示可能会以Hello World"开头,但仅此而已.
Which platform? If it was Windows and CMD.EXE, then all sorts of things could be going wrong. On a Unix-like platform, that should work fine. No newline at the end, so it's likely your prompt would appear to start with 'Hello World', but that's all.
加上注释说是Windows,那么麻烦的是Windows CMD.EXE不像Unix那样解析命令行,不能简单地用单引号将参数括起来;你必须使用双引号.试试:
With the comment that it is Windows, then the trouble is that Windows CMD.EXE does not parse the command line the same as Unix, and you can't simply use single quotes around arguments; you have to use double quotes. Try:
perl -e "print qq{Hello World
}"
它对您有用的可能性不大.
There's a modest chance it will work for you.
这篇关于为什么这个 Perl one-liner 在 Windows 上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!