如何启动Perl的交互式控制台,类似于Ruby的irb命令或python的python命令?


当前回答

如果需要历史记录,请使用rlwrap。这可以是你的~/bin/ips,例如:

#!/bin/sh
echo 'This is Interactive Perl shell'
rlwrap -A -pgreen -S"perl> " perl -wnE'say eval()//$@'

这是它的样子:

$ ips
This is Interactive Perl shell
perl> 2**128
3.40282366920938e+38
perl> 

其他回答

我使用命令行作为控制台:

$ perl -e 'print "JAPH\n"'

然后,我可以使用bash历史记录获取旧命令。然而,这并不能保存状态。

当您想测试“一件小事”(比如回答Perl问题)时,这个表单最有用。我经常发现这些命令被逐字逐句地复制到shell脚本或makefile中。

Perl -d是你的朋友:

% perl -de 0

我已经创建了perli,一个运行在Linux、macOS和Windows上的Perl REPL。

它的重点是自动打印结果,方便的文档查找,并且简单 检查正则表达式匹配。 你可以在这里看到截图。

它可以独立工作(除了Perl本身,没有其他依赖项),但是强烈建议安装rlwrap,以便支持命令行编辑、持久的命令历史记录和制表符补全——在这里阅读更多信息。

安装

If you happen to have Node.js installed: npm install -g perli Otherwise: Unix-like platforms: Download this script as perli to a folder in your system's path and make it executable with chmod +x. Windows: Download the this script as perli.pl (note the .pl extension) to a folder in your system's path. If you don't mind invoking Perli as perli.pl, you're all set. Otherwise, create a batch file named perli.cmd in the same folder with the following content: @%~dpn.pl %*; this enables invocation as just perli.

参见时髦的REPL(适用于GNU Emacs)

在 Debian/Ubuntu 下:

$ sudo apt-get install libdevel-repl-perl
$ re.pl

$ sudo apt-get install libapp-repl-perl
$ iperl