命令python -i script.py
将运行给定的脚本,然后将我放入交互式repl中,脚本中的函数和变量可访问。是否有Perl类似物?
修改:如果有帮助,请参阅python -i
https://docs.python.org/3.4/using/cmdline.html#cmdoption-i
当脚本作为第一个参数传递或使用-c选项时,在执行脚本或命令后进入交互模式,即使sys.stdin似乎不是终端。未读取PYTHONSTARTUP文件。
当脚本引发异常时,这对于检查全局变量或堆栈跟踪非常有用
答案 0 :(得分:3)
perl -d script.pl
并且点击c<ENTER>
可能足够接近,
c [ln|sub] Continue until position
perl -MData::Dumper -de '%h = 1..4'
Loading DB routines from perl5db.pl version 1.44
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(-e:1): %h = 1..4
DB<1> print Dumper \%h
$VAR1 = {};
DB<2> c
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
DB<2> print Dumper \%h
$VAR1 = {
'3' => 4,
'1' => 2
};
答案 1 :(得分:3)
除了mpapec提到的Perl调试器shell之外,CPAN上还有几个REPL实现。其中两个更好的是:
以下是使用回复的示例:
$ reply -MJSON::PP -MHTTP::Tiny 0> my $json = JSON::PP->new; $res[0] = bless( { 'FLAGS' => 0, 'fallback' => sub { "DUMMY" }, 'indent' => 0, 'indent_length' => 3, 'max_depth' => 512, 'max_size' => 0 }, 'JSON::PP' ) 1> my $ua = HTTP::Tiny->new; $res[1] = bless( { 'agent' => 'HTTP-Tiny/0.043', 'keep_alive' => 1, 'max_redirect' => 5, 'no_proxy' => [], 'timeout' => 60, 'verify_SSL' => 0 }, 'HTTP::Tiny' ) 2> $json->decode( $ua->get("http://api.metacpan.org/v0/release/TOBYINK/Type-Tiny-0.044")->{content} )->{resources}; $res[2] = { 'bugtracker' => { 'web' => 'http://rt.cpan.org/Dist/Display.html?Queue=Type-Tiny' }, 'homepage' => 'https://metacpan.org/release/Type-Tiny', 'license' => [ 'http://dev.perl.org/licenses/' ], 'repository' => { 'type' => 'git', 'url' => 'git://github.com/tobyink/p5-type-tiny.git', 'web' => 'https://github.com/tobyink/p5-type-tiny' } }
您会注意到这不会运行您的脚本并在之后将您放入REPL。它只是带你直接到REPL。但是从那里你可以通过输入require "myscript.pl"
来运行脚本。