原文:
17.2 Is there something equivalent to wish in perl/Tk?
The answer is yes.
The idea of wish is that you read from <STDIN> and evaluate each statement. The standard way to do this in perl/Tk is to use the tkpsh script that comes in your perl/Tk build directory. Another elegant way to get wish like behavior in perl/Tk is to use rmt which you can find in perl5/Tk/demos in your perl/Tk distribution. When you run rmt you already have Tk.pm set up for you so you can start typing things like $mmm = new MainWindow; etc. at the rmt: prompt. (This use belies the power of rmt which is derived from Ousterhout's Tcl/Tk version of rmt [see section 27.2 of his book]. rmt is capable of "inserting Tk code" into simultaneously running Tk applications.)
A cruder way to get wish-like behaviour with perl/Tk is to run a "perl shell" and type in your usual commands, including use Tk; etc. There is a script distributed with perl called perlsh which is written quite simply as: #!/usr/bin/perl $/ = ''; # set paragraph mode $SHlinesep = "\n"; while ($SHcmd = <>) { $/ = $SHlinesep; eval $SHcmd; print $@ || "\n"; $SHlinesep = $/; $/ = ''; }
You can use this during code development to test out little snippets of code. It helps to be an accurate typist and the use strict; is optional here :-)
KOBAYASI Hiroaki has a more sophisticated wish like perl/Tk "shell" that is called EVA. It is available from: ftp://ftp.sowa.is.uec.ac.jp/pub/Lang/perl5/Tk/
译文:
17.2. Perl/Tk中有相当于wish的shell吗?
答案是——有!
wish 的基本原则就是从标准输入STDIN读入命令,逐条执行。实现这个目标的标准的方法是使用你的Perl/Tk安装目录里自带的ptksh脚本。另一个在 Perl/Tk中实现类似wish的shell的更好方法是使用你的Perl/Tk目录里的demos中的rmt……(但是,我没有找到这个,也不太清楚这究竟是什么……所以这里就略过了。)
另一个比较原始的实现方法是运行一个“perl shell”,然后输入你常规的命令(包括use Tk;等等)。有一个叫做perlsh的脚本是跟随Perl一起发布的,它其实非常简单,内容如下:
#!/usr/bin/perl
$/ = ''; # set paragraph mode
$SHlinesep = "\n";
while ($SHcmd = <>) {
$/ = $SHlinesep;
eval $SHcmd; print $@ || "\n";
$SHlinesep = $/; $/ = '';
}
你也许可以在开发时使用它来测试一些代码片断。它还可以帮助检查输入的准确性(?),这里use strict;是可选的。
KOBAYASI Hiroaki写了一个更加成熟的类似wish的Perl/Tk“shell”,名为EVA。可以从下面的网址获得:
ftp://ftp.sowa.is.uec.ac.jp/pub/Lang/perl5/Tk/