in reply to Re: (tye)Re: Ordered Comparison of Generalized Version Strings.
in thread Ordered Comparison of Generalized Version Strings.
Well it is trivial to make mine case insensitive. And I think mine makes better sense. Your routine considers 1.3 < 1.3a < 1.3a.2 but refuses to compare 1.3.4 to 1.3a.2. That seems inconsistant to me. I think that mine agrees with yours in all cases where yours will make a comparison.
Mine works for lots of types of strings but not strings that contain control characters, negative numbers, digit strings larger than 0.5G, numbers with embedded commas, numbers in scientific notation, fractions, or numbers with different numbers of digits after the decimal point.
There are quite a few variations on this "theme" that I've used at different times. If you need to support numbers of around 8000 digits, then you can use this one (that also ignores case):
- tye (but my friends call me "Tye")sub compare_versions { my( $left, $right )= map lc, @_; for( $left, $right ) { s/(\d+)/pack("n",length$1).$1/ge; } return $left cmp $right; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (tye)Re2: Ordered Comparison of Generalized Version Strings.
by John M. Dlugosz (Monsignor) on Jul 26, 2001 at 19:16 UTC | |
by tye (Sage) on Jul 26, 2001 at 19:49 UTC |