简体   繁体   English

当出现Shebang行时,Perl“ Hello World”不起作用(Windows)

[英]Perl 'hello world' doesn't work when shebang line present (Windows)

I'm running ActiveState Perl 5.10.1 on Windows XP. 我在Windows XP上运行ActiveState Perl 5.10.1。

The following program executes, but produces no output at the command line: 执行以下程序,但在命令行上不产生任何输出:

#!c:/perl/bin/perl.exe

use strict;
use warnings;

print "foo\n";

If I remove the shebang line, I get 'foo' shown as the output, as expected. 如果删除shebang行,则按预期将“ foo”显示为输出。

I get the same result if I execute using file association only ( foo.pl ), referencing perl via PATH ( perl foo.pl ) or even directly referring to the perl executable ( c:\\perl\\bin\\perl.exe foo.pl ). 如果仅使用文件关联( foo.pl ),通过PATH引用perl( perl foo.pl )甚至直接引用perl可执行文件( c:\\perl\\bin\\perl.exe foo.pl )。

I don't understand why the script works without the shebang line, but I get no output when the shebang line is present. 我不明白为什么脚本没有shebang行就可以工作,但是当shebang行出现时却没有输出。 My understanding is that the shebang line isn't strictly necessary for Perl in Windows, but it's considered good practice in case you want to use switches like -w ... 我的理解是,对于Windows中的Perl来说,shebang行不是严格必需的,但是如果您要使用-w等开关,这是一种很好的做法。

It makes no difference if I explicitly make the handle STDOUT, ie print STDOUT "foo\\n"; 如果我明确地使句柄为STDOUT,即print STDOUT "foo\\n"; ,则没有任何区别print STDOUT "foo\\n";

This is driving me absolutely crazy; 这真让我发疯。 any tips would be appreciated. 任何提示将不胜感激。

The program I gave you was incorrect. 我给你的程序不正确。 It should have been 应该是

perl -0777nE"BEGIN { binmode STDIN }; say unpack 'H*', $_" <foo.pl

But it still revealed the problem. 但这仍然揭示了问题所在。 Your lines are terminated by carriage returns (0D) instead of CRLF (0D0A)! 您的行以回车符(0D)代替CRLF(0D0A)终止!

2321633a2f7065726c2f62696e2f7065726c2e6578650d
0d
757365207374726963743b0d
7573652‌​07761726e696e67733b0d
0d
7072696e742022666f6f5c6e223b0d
0d

To Perl, that's all one line. 对于Perl来说,这就是一行。 That's right, your entire program is a very long shebang line. 是的,您的整个程序的排行很长。

Switch from MacOS line endings (a machine that was obsolete 10 years ago) to Windows lines endings, and your problem should go away. 从MacOS行尾(一台在10年前已淘汰的机器)切换到Windows行尾,您的问题就应该消除了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM