Created
February 13, 2019 20:40
-
-
Save CaViCcHi/d44a0231744d2063863765a0fd37866c to your computer and use it in GitHub Desktop.
perl version comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# (before, after) if after > before; then return 1; else return 0; | |
sub is_newer_version | |
{ | |
my $before = shift; | |
my $after = shift; | |
_llog("Comparing versions ($before - $after)"); | |
my @b = split(/\./, $before); | |
my @a = split(/\./, $after); | |
my $cntb = scalar(@b); | |
for(my $j; $j<$cntb; $j++) | |
{ | |
if(!exists($a[$j])) | |
{ | |
my $k=int($j+1); | |
while(int($b[$k]) == 0) | |
{ | |
if(!exists($b[$k+1])) | |
{ | |
last; | |
} | |
$k++; | |
} | |
if(int($b[$k]) == 0) | |
{ | |
_llog("The versions are identical($before - $after), returning no"); | |
return 0; | |
} | |
return 0; | |
} | |
if(int($a[$j]) > int($b[$j])) | |
{ | |
return 1; | |
} | |
if(int($a[$j]) < int($b[$j])) | |
{ | |
return 0; | |
} | |
if(exists($a[$j+1]) && !exists($b[$j+1])) | |
{ | |
my $k=int($j+1); | |
while(int($a[$k]) == 0) | |
{ | |
if(!exists($a[$k+1])) | |
{ | |
last; | |
} | |
$k++; | |
} | |
if(int($a[$k]) == 0) | |
{ | |
_llog("The versions are identical($before - $after), returning no"); | |
return 0; | |
} | |
return 1; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment