I'm running ActiveState Perl 5.10.1 on Windows XP.

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.

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).

I don't understand why the script works without the shebang line, but I get no output when the shebang line is present. 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...

It makes no difference if I explicitly make the handle STDOUT, i.e. 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)!

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

To Perl, that's all one line. 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top