Perl/TkFAQ-12.5有什么办法能够了解Perl/Tk的路径中有哪些模块吗?
来源:linux宝库作者:linux宝库 发布时间:2007-09-30 00:00:00


原文:
12.5. Is there a way to find out what is in my perl/Tk "PATH"?
Presuming this question is asking for a little more than the answer you get when you type: ls perl5/lib/Tk/*.pm
there are ways to find out what gets EXPORTED by Tk.pm. Use a script like: #!/usr/bin/perl use Tk; require ’dumpvar.pl’; dumpvar(’Tk’);
or more succintly at the shell command prompt: perl -e ’use Tk; require "dumpvar.pl"; dumpvar("Tk");’
The advantage of using dumpvar over ls is that it gives you a brief summary of all the arguments your widgets want. Note that the output is many lines and you may wish to pipe through more or less.
If you wish to determine the Configuration options a given widget accepts (and what the values are at a given point in a script) you may use the ->configure method with no arguments to retrieve the list of lists, as in this example: #!/usr/bin/perl use Tk; my $main = MainWindow -> new; my $scrl = $main -> Scrollbar(’-orient’ => ’horizontal’); @scrollconfig = $scrl -> configure; for (@scrollconfig) { print "@$_\n"; } etc.
Such code is useful for development but is probably best left out, commented out, or switched out of "production line" code.
译文:
12.5 有什么办法能够了解Perl/Tk的路径中有哪些模块吗?
其实答案很简单,只要在命令行里输入:
ls perl5/lib/Tk/*.pm
但是,我们不妨考虑的更深入一些,能够用下面的简单脚本来了解Tk.pm输出(Export)了哪些:
#!/usr/bin/perl
use Tk;
require ’dumpvar.pl’;
dumpvar(’Tk’);
或能够更简便的,就在命令行中使用如下命令:
perl -e ’use Tk; require "dumpvar.pl"; dumpvar("Tk");’
(译者注:在Windows系统中需要这样使用:
perl -e "use Tk; require ’dumpvar.pl’;dumpvar(’Tk’);")
使用dumpvar比ls的好处就在于,他能够简单的给出您的组件可能涉及的任何参数的值。请注意,他的输出有很多行,所以您可能需要使用more或less来进行分屏显示。
假如您想知道一个给定的组件的任何配置选项(连同在脚本中的某处的其所对应的值),那么您能够不带任何参数的使用->configure方法,从而能够获得一个选项和当前值的列表。如下例:
#!/usr/bin/perl
use Tk;
my $main = MainWindow -> new;
my $scrl = $main -> Scrollbar(’-orient’ => ’horizontal’);
@scrollconfig = $scrl -> configure;
for (@scrollconfig) {
print "@$_\n";
}
……
当然,这样的代码对于我们研发时很有用,但是在实际的脚本中可能必须删掉或注释掉相应的代码了。
|
还没有关于此文章的相关评论!