简体   繁体   English

Perl:当我从命令行运行“perl”时没有任何反应

[英]Perl: Nothing happens when I run “perl” from the command line

If I run perl by itself from the linux command line, nothing happens. 如果我从linux命令行自行运行perl ,则没有任何反应。 I see the cursor move down a line and if I enter print "Hello, world"; 我看到光标向下移动一行,如果我输入print "Hello, world"; , still nothing happens. ,仍然没有任何反应。 Is there anything I can input from the command line from here? 我可以从命令行输入任何内容吗? I know that you can run perl -e 'print "Hello, world"'; 我知道你可以运行perl -e 'print "Hello, world"'; and how to create a perl script. 以及如何创建perl脚本。 Just wondering why running perl by itself does nothing. 只是想知道为什么运行perl本身什么都不做。

Type the following: 输入以下内容:

$ perl
print "Hello World\n";
Ctrl-D
Hello World
$

That's last line is you holding down the Control key and pressing D . 最后一行是按住Control键并按D键。 Not typing Ctrl-D . 不输入Ctrl-D

If you type stty -a , you'll see that Ctrl-D is he EOF character. 如果你键入stty -a ,你会看到Ctrl-D是他的EOF字符。 That's Perl reading in a file from STDIN. 这是Perl从STDIN读取的文件。 Is that what you want? 那是你要的吗?

On my system (Windows, cmd shell) if I just type perl it starts to read code from STDIN, and when I hit end of file Ctrl-Z, it executes the code. 在我的系统(Windows,cmd shell)上,如果我只输入perl它就开始从STDIN读取代码,当我点击文件末尾Ctrl-Z时,它会执行代码。 As demonstrated here: 如下所示:

C:\perl>perl
$a = "asd";
print "\$a = '$a'";
^Z
$a = 'asd'
C:\perl>perl
use Data::Dumper;
print Dumper [ 3.14 ];
^Z
$VAR1 = [
          '3.14'
        ];

This is handy, because normally I can't use double quotes in the cmd shell without quoting issues. 这很方便,因为通常我不能在没有引用问题的情况下在cmd shell中使用双引号。

Run perl by itself in Linux command line, perl will wait for your input, as exampled by the answer given by @david-w 在Linux命令行中自己运行perlperl将等待你的输入,例如@ david -w给出的答案

If you want a interactive Perl environment, you can start perl in debugging mode by perl -d -e 42 , or install Perl Shell(psh) . 如果您需要交互式Perl环境,可以通过perl -d -e 42在调试模式下启动perl,或者安装Perl Shell(psh)

Run perldoc perlrun and perldoc perldebug for further details. 有关详细信息, perldoc perldebug运行perldoc perlrunperldoc perldebug

Try: 尝试:

perl -e "print 'Hello World';"

Otherwise, just entering perl doesn't really do anything. 否则,只是输入p​​erl并没有真正做任何事情。 (That I know of, mines does the same as yours) (我知道,地雷和你的一样)

I think you're looking for perl shell.. aka PSH 我想你正在寻找perl shell ..又名PSH

https://metacpan.org/pod/distribution/psh/doc/psh.pod https://metacpan.org/pod/distribution/psh/doc/psh.pod

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

相关问题 从命令行运行特定的Perl脚本 - run specific perl script from command line Perl 命令在命令行上运行时执行良好但在 Perl 脚本中不起作用 - Perl command executing good when run on command line but not working in the Perl script 如果我从图标运行它与从命令行运行它,为什么我的perl脚本的行为会有所不同? - Why does my perl script behave differently if I run it from the icon vs running it from the command line? 如何在不使用命令行的情况下运行 Perl 脚本? - How can I run a Perl script without using the command line? 计划任务以从命令行运行 perl 脚本 - schedule task to run perl script from command line 如何使用命令行参数从bash运行perl脚本? - How can I run a perl script from bash using command line arguments? 一个perl命令行,用于打印用于运行脚本的perl版本 - A perl command line that prints the perl version it is using to run your script perl @ARGV在命令行上工作,但从其他应用程序传递时不行 - perl @ARGV works on command line, but not when passed from another application 从命令行运行Talend perl作业时丢失文件 - Missing files when running a Talend perl job from the command line 从Perl执行命令行命令? - execute command line command from Perl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM