perl --version
打印所有这些:
This is perl 5, version 26, subversion 1 (v5.26.1) built for darwin-thread-multi-2level
Copyright 1987-2017, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
我想要的是:
5.26.1
是否有任何开箱即用的方法,或者我是否需要编写自己的正则表达式以从详细输出中提取它?
答案 0 :(得分:7)
变量$^V包含该信息。您可以直接从Perl中打印出来:
#!/usr/bin/perl
use strict;
use warnings;
print $^V;
或者你可以用bash获得它:
perl -e 'print $^V'
两个版本都在我的系统上打印“v5.22.1”。
答案 1 :(得分:6)
perl -e'print substr($^V, 1)' # 5.10+
perl -MConfig -e'print $Config{version}'
答案 2 :(得分:6)
除$^V
和$Config{version}
外,还有$]
,其中包含版本的数值。
$ perl -MConfig -E 'say for $], $^V, $Config{version}'
5.016003
v5.16.3
5.16.3