Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Comparing some version numbers for a post on http://blogs.perl.org/users/chisel
#!/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;
@wols

This comment has been minimized.

Show comment Hide comment
@wols

wols Feb 26, 2016

Thanks for post here.

wols commented Feb 26, 2016

Thanks for post here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment