in reply to Re: Why not include version.pm
in thread Why not include version.pm

In the 'installer' Perl script, very early on, I check for the installed version of Perl. I need to trap this result in the application and explain to the person who is doing the install what the problem is, even if they don't know Perl.

I don't remember where I found this but it tells me if the installed Perl is 5.12 or higher.

use version; ... sub checkPerlVer { my $minVer = shift; # eg '5.12' my $installVer = `perl -v|grep -E '(v[1-9.]+)'`; if ($installVer =~ /\((v[\d+.]+)\)/){ #print "match $1\n"; my $reVer = $1; my $iver= version->parse($reVer); my $mver= version->parse($minVer); printf "Minimum Perl=$mver Installed Perl=$iver \n"; if ($mver <= $iver) { print "OK \n"; return 1; #OK }else{ print "NOPE\n"; return 0; #NOT OK } }else{ print "No version found: <$installVer>\n"; return 0; } }

It is always better to have seen your target for yourself, rather than depend upon someone else's description.

Replies are listed 'Best First'.
Re^3: Why not include version.pm
by Corion (Patriarch) on Mar 28, 2016 at 12:27 UTC

    Ugh. This might return you the version of a different Perl executable than the one your script is run with.

    Why not use the $] variable, as documented in perlvar?

    print "Running under Perl $]\n";

    You will need to change your version check from '5.12' to '5.012' though, because that's what $] will contain.

      Thanks, followed your advice, a few less lines needed and probably more correct.

      It is always better to have seen your target for yourself, rather than depend upon someone else's description.