原文:
12.9. How do I determine the version of perl/Tk that I am running?
With an up to date perl installation one may query the local perl setup and all extensions via the command: perldoc perllocal
For the Tk extension: version numbering has changed recently and determining the version of perl/Tk that you are running now depends on what version you are running:
Tk-b10++:
Tk-b10 (and higher) has changed to $Tk::VERSION (rather than the older "$Tk:Version") to be consistent with other packages. Hence a short succinct way to tell which version you have installed (that works with Tk-b11 and Tk400.200) is: perl -MTk -e 'print $Tk::VERSION."\n"'
Tk-b9.01:
The version numbers as of Tk-b9.01 are stored in the following variables: Core Tk version : $Tk::version Tk patchLevel : $Tk::patchLevel library : $Tk::library perl/Tk Version : $Tk::Version
At your shell prompt you could say something like the following to determine you perl/Tk Version: perl -e 'use Tk; print "$Tk::Version\n";'
The switch to Tk-b9.01 from previous versions included a large number of method name changes. Nick was kind enough to include a b9names script in the distribution that assists with the job of updating your older scripts. See the b9names script for a rather complete discussion of the name changes. Geoffroy Ville also posted a notice of some of the changes. Here is a brief (and very incomplete!) summary: older Tk-b9.01++packslaves pack('slaves')packpropagate pack('propagate')packForget pack('forget') pack('info')$w->delete if ($w); $w->destroy if ($w);
Tk-b8(--):
A little script (Tk_module) can tell you and return the value: #!/usr/bin/perl use Tk; local(*Tk_m) = \$Tk::Tk_module; print "$Tk_m\n";
Or more succintly say something like the following (at your shell prompt): perl -e 'use Tk; print "$Tk::Tk_module\n";'
You can obtain the version of Tk in use with the following (at your shell prompt): perl -e 'use Tk; print "$Tk::tk_version\n";'
where this command returned "4.0" when the previous one (or Tk_module) returned "b8".
All Tk versions:
Don't forget that you can always determine your Perl version/patchlevel/etc. with: perl -v
(at the shell prompt - it's actually a little harder to get as much information from within a #!script.) As of perl 5.002 you can use perl -V to determine your perl Configuration.
OZAWA Sakuro mailtp:ozawa@prince.pe.u-tokyo.ac.jp points out some ways to do it in a script:
1. '$]' holds the version number.
2. In Perl5, 'require NUMBER;' will complain if version is younger than NUMBER. (e.g. require 5.001;)
3. Of course, newly imported (and incompatible) features in newer scripts will bailout before execution if parsed by an old interpreter.
Note that if you use English; then $PERL_VERSION holds the version number.
To determine your MakeMaker version number try something like this (5.002): perl -MExtUtils::MakeMaker -e 'print "$ExtUtils::MakeMaker::VERSION\n";'
or this (5.001m ok): perl -e 'use ExtUtils::MakeMaker;print"$ExtUtils::MakeMaker::VERSION\n";'
or even this (older perls and MakeMakers): perl -e 'use ExtUtils::MakeMaker;print"$ExtUtils::MakeMaker::Version\n";'
Please note that thoughout this FAQ document there are references to things like Tk-b10(++) or Tk-b10++ which roughly translated to use English; means something like "I think this will work with this version of Tk and (maybe) higher versions...". You might also see Tk-b8(--) which means something like "it worked with that old version and probably worked with prior versions and if you are stuck with an old Tk version you might have to do it this way...".
译文:
12.9 如何了解我所使用的Perl/Tk的版本?
如果你的系统上已经安装了新近版本的Perl,那么你可以通过如下的命令行操作来查询你的本地Perl所安装的扩展模块情况:
perldoc perllocal
而对于如何知道Tk模块的版本,因为它的设置随其版本的不同而有一些变化,所以需要依各种情况而定。(译者注:因为这个FAQ创作的年代比较早,所以有些内容已经过时了。据我所知,目前CPAN所提供的Perl/Tk的版本都是8.0以后的。因此,这里我们略去了那些关于老本版的内容。)
对于Perl本身的版本,修订号等等的信息,我们可以通过在命令行中使用:
perl –v
来获得。而对于5.002以后的Perl版本,还可以使用perl –V来了解Perl的配置情况。
OZAWA Sakuro给出了一些可以在脚本中用来测试Perl版本的方法:
1.内置变量$]即为Perl的版本号;
2.在Perl5中,使用语句’require XXX(数字);’将会在Perl版本低于XXX时报错;
3.当然,如果你在脚本中使用了一些新引入的特性,那么做老的Perl解释器下运行时也会报错的。
对于目前广泛使用的Perl/Tk,我们可以在命令行中使用如下的简单方法来获得其版本号:
perl -e "use Tk; print $Tk::VERSION;" (Windows系统)
perl -e 'use Tk; print $Tk::VERSION;' (Unix/Linux系统)