如何在没有许可证和构建信息的情况下获取Perl版本字符串?

Dav*_*les 3 perl

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.
Run Code Online (Sandbox Code Playgroud)

我想要的是这个:

5.26.1
Run Code Online (Sandbox Code Playgroud)

是否有任何开箱即用的方法,或者我是否需要编写自己的正则表达式从详细输出中提取它?

pco*_*ley 7

变量$ ^ V具有该信息.你可以直接从Perl里面打印出来:

#!/usr/bin/perl

use strict;
use warnings;

print $^V;
Run Code Online (Sandbox Code Playgroud)

或者你可以用bash获得它:

perl -e 'print $^V'
Run Code Online (Sandbox Code Playgroud)

两个版本都在我的系统上打印"v5.22.1".


ike*_*ami 6

perl -e'print substr($^V, 1)'      # 5.10+

perl -MConfig -e'print $Config{version}'
Run Code Online (Sandbox Code Playgroud)


mob*_*mob 6

除了$^V和之外$Config{version},还有$],它包含版本的数值.

$ perl -MConfig -E 'say for $], $^V, $Config{version}'
5.016003
v5.16.3
5.16.3
Run Code Online (Sandbox Code Playgroud)