Created
January 30, 2013 23:31
-
-
Save chizmw/4678385 to your computer and use it in GitHub Desktop.
Comparing some version numbers for a post on http://blogs.perl.org/users/chisel
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature ':5.12'; | |
use version; | |
use Text::SimpleTable; | |
my @versionstrings = ( | |
'0.0.4', | |
'0.0.5', | |
'0.0.5_01', | |
'0.0.5_50', | |
'0.0.5_99', | |
'0.0.5', | |
'0.0.6', | |
); | |
my @versions; | |
foreach my $vstring (@versionstrings) { | |
push @versions, version->parse($vstring); | |
} | |
my $t1 = Text::SimpleTable->new( | |
[12, 'Input String'], | |
[12, 'normal()'], | |
[14, 'cmp-prev'], | |
[14, 'cmp-next'], | |
); | |
for (my$i=0; $i<@versions; $i++) { | |
my $cmp_with_prev; | |
if($i>0) { | |
given ($i) { | |
when ($versions[$i] < $versions[$i-1]) { | |
$cmp_with_prev = "< " . $versions[$i-1]; | |
} | |
when ($versions[$i] == $versions[$i-1]) { | |
$cmp_with_prev = "== " . $versions[$i-1]; | |
} | |
when ($versions[$i] > $versions[$i-1]) { | |
$cmp_with_prev = " > " . $versions[$i-1]; | |
} | |
} | |
} | |
else { | |
$cmp_with_prev = ''; | |
} | |
my $cmp_with_next; | |
if($i<@versions-1) { | |
given ($i) { | |
when ($versions[$i] < $versions[$i+1]) { | |
$cmp_with_next = "< " . $versions[$i+1]; | |
} | |
when ($versions[$i] == $versions[$i+1]) { | |
$cmp_with_next = "== " . $versions[$i+1]; | |
} | |
when ($versions[$i] > $versions[$i+1]) { | |
$cmp_with_next = " > " . $versions[$i+1]; | |
} | |
} | |
} | |
else { | |
$cmp_with_next = ''; | |
} | |
$t1->row( | |
$versionstrings[$i], | |
$versions[$i]->normal, | |
$cmp_with_prev, | |
$cmp_with_next, | |
); | |
} | |
say $t1->draw; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for post here.