如何启动Perl的交互式控制台,类似于Ruby的irb命令或python的python命令?
当前回答
我已经创建了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.
其他回答
Matt Trout的概述列出了五个选择,从perl -de 0开始,如果通过插件扩展是重要的,他推荐Reply,或者Eval::WithLexicals的tinyrepl,这是一个最小的、纯perl的解决方案,包括readline支持和词汇持久性。
还可以在CPAN上查找ptkdb: http://search.cpan.org/search?query=ptkdb&mode=all
Read-eval-print循环:
$ perl -e'while(<>){print eval,"\n"}'
你可以在emacs中使用org-babel;打开一个组织模式文件,即tmp.org,然后你可以这样做:
#+begin_src perl :results output
@a = (1,5,9);
print ((join ", ", @a) . "\n");
$b = scalar @a;
print "$#a, $b\n";
print "$#a, " . @a . "\n";
print join ", ", 1..$#a; print "\n";
print join ", ", @a[0..$#a]
#+end_src
按CTRL-c CTRL-c将计算该块:
#+RESULTS:
#+begin_example
1, 5, 9
2, 3
2, 3
1, 2
1, 5, 9
#+end_example
我不确定这需要什么emacs配置,但我认为您可以安装https://github.com/hlissner/doom-emacs并启用它的perl和org-mode模块。
如果需要历史记录,请使用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>
推荐文章
- console.log()和console.debug()的区别?
- 如何禁用标准错误流的日志记录?
- 在Perl中,“my”和“our”的区别是什么?
- 为什么“System.out。”println“工作在Android?
- 如何在保持原始字符串的同时对字符串执行Perl替换?
- 如何在Visual c++中保持控制台窗口打开?
- Perl的@INC是如何构造的?(又名:影响Perl模块搜索位置的所有方法是什么?)
- 如何停止c++控制台应用程序从退出立即?
- 从输出中删除颜色
- Chrome: console.log, console.debug不工作
- 访问控制台和扩展的后台开发工具
- 将Chrome中的console.log保存为文件
- 清除javascript控制台在谷歌Chrome
- 安装缺少的Perl模块最简单的方法是什么?
- 我如何才能快速和所有的数字在一个文件?