简体   繁体   English

来自STDIN管道的perl输入仅适用于脚本前面的perl

[英]perl input from STDIN pipe only works with perl in front of script

I am attempting to read from STDIN with a perl script. 我正在尝试使用Perl脚本从STDIN中读取。

Here is the script I am using for testing: 这是我用于测试的脚本:

#!/usr/bin/perl

foreach $line (<>) 
{
  print $line;
}

So from the command prompt, I type: 因此,在命令提示符下,键入:

> cat somefile | testscript
>

It returns nothing with no error. 它不返回任何错误。

I then type the following: 然后输入以下内容:

> cat somefile | perl testscript
> *the contents of the file are printed line by line*

I really do not want the users to have to append perl in front of the script if I do not have to. 我真的不想让用户不必在脚本前附加perl。

Thanks for reading. 谢谢阅读。

I think you run two different versions of Perl. 我认为您运行两种不同的Perl版本。 What is the output of "which perl"? “哪个perl”的输出是什么?

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

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