[英]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命令行中自己运行
perl
, perl
将等待你的输入,例如@ 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 perlrun
和perldoc perldebug
。
Try: 尝试:
perl -e "print 'Hello World';"
Otherwise, just entering perl doesn't really do anything. 否则,只是输入perl并没有真正做任何事情。 (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.