Skip Menu |
 

This queue is for tickets about the Sort-Versions CPAN distribution.

Report information
The Basics
Id: 57250
Status: open
Priority: 0/
Queue: Sort-Versions

People
Owner: Nobody in particular
Requestors: email [...] froggs.de
Cc: email@froggs.de (no email address)
AdminCc:

Bug Information
Severity: Important
Broken in: 1.5
Fixed in: (no value)



CC: email [...] froggs.de
Subject: versioncmp and v1.2.3-style version
Download (untitled) / with headers
text/plain 318b
Hi, looks liek versioncmp has a problem with 'v1.2.3' sytle versions. See: perl -MSort::Versions -e"print versioncmp(1.403, 'v1.4.1')" -1 perl -MSort::Versions -e"print versioncmp(1.403, '1.4.1')" 1 But it should be: a) always the same reslut b) 1.4.1 == 1.004001 c) 1.004001 < 1.403000 Thanks in advance, FROGGS
From: kfm [...] plushkava.net
Download (untitled) / with headers
text/plain 1001b
On Thu May 06 03:09:33 2010, FROGGS wrote: Show quoted text
> Hi, looks liek versioncmp has a problem with 'v1.2.3' sytle versions. > > See: > > perl -MSort::Versions -e"print versioncmp(1.403, 'v1.4.1')" > -1 > > perl -MSort::Versions -e"print versioncmp(1.403, '1.4.1')" > 1 > > But it should be: > a) always the same reslut
I wonder whether it would be acceptable to transform both parameters with s/^v(\d)/$1/ prior to processing, as in the attached patch. Before: # perl -MSort::Versions -e "print versioncmp ('1.1', 'v1.0')" -1 The problem here is that it begins by lexically comparing '1' to 'v', resulting in the latter being treated as the greater version. After: # perl -MSort::Versions -e "print versioncmp ('1.1', 'v1.0')" 1 Show quoted text
> b) 1.4.1 == 1.004001 > c) 1.004001 < 1.403000 >
Perl::Version would likely suit your needs. It is able to directly compare fielded version numbers. It also has a "normal" method that stringifies in a manner that allows for comparison against regular version numbers.
Subject: sort-versions-drop-v.patch
--- Versions.pm 2015-04-29 22:14:43.000000000 +0100 +++ /home/kerin/Versions.pm 2015-04-30 02:02:47.084816500 +0100 @@ -14,10 +14,12 @@ our @EXPORT_OK = qw(); sub versioncmp ($$) { - my @A = ($_[0] =~ /([-.]|\d+|[^-.\d]+)/g); - my @B = ($_[1] =~ /([-.]|\d+|[^-.\d]+)/g); + my ($A, $B) = @_; + $A =~ s/^v(\d)/$1/; + $B =~ s/^v(\d)/$1/; + my @A = ($A =~ /([-.]|\d+|[^-.\d]+)/g); + my @B = ($B =~ /([-.]|\d+|[^-.\d]+)/g); - my ($A, $B); while (@A and @B) { $A = shift @A; $B = shift @B;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.