Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check perl version

Tags:

version

perl

the default Perl version installed on my machine is the 5.8.7. When I run my script internally switch to another perl version (v5.10.1) doing this:

  my $perl_5_10 = "/opt/perl_5.10.1/bin";
  $ENV{'PATH'}  = $perl_5_10 ":" . $ENV{'PATH'};

Now, I have to check the perl version, and I do:

   ## PERL: need perl version >= 5.10!
   if ($] < 5.010000)
   {
     ## VERSION ERROR!
   }

   my $perl_cmd = "perl --version";
   my $perl_str=`$perl_cmd`;
   print "PERL VERSION = " . $perl_str;   ## this clearly print 5.10.1

it return error as the version used is 5.8.7 and that's pretty normal as I ran my script with that version. But my problem is:

how can I check that the new perl version is >= 5.10.1 ?

like image 247
Kasper Avatar asked Jun 26 '26 05:06

Kasper


1 Answers

The first 3 decimals are the subversion, and second 3 decimals are revision. Therefore use

if ($] >= 5.010001)
{
    ## We're all good.  Greater than 5.10.1
}

I primarily use 5.18.2, and therefore my $] equals 5.018002.

For alternative methods check out perlvar $PERL_VERSION or $^V and use VERSION

like image 136
Miller Avatar answered Jun 28 '26 14:06

Miller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!