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.