Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: (tye)Re: Ordered Comparison of Generalized Version Strings.

by John M. Dlugosz (Monsignor)
on Jul 26, 2001 at 02:28 UTC ( [id://99832]=note: print w/replies, xml ) Need Help??


in reply to (tye)Re: Ordered Comparison of Generalized Version Strings.
in thread Ordered Comparison of Generalized Version Strings.

Cute. I don't expect any numbers larger than 4G in a version string! But, it's not case-insensitive, and doesn't validate that left and right are in the same format (you get a bogus result if they are not).

I don't know if I can use a trick like this to simplify it and still keep the error check. The check pretty much demands that each part be inspected so it can be categorized.

  • Comment on Re: (tye)Re: Ordered Comparison of Generalized Version Strings.

Replies are listed 'Best First'.
(tye)Re2: Ordered Comparison of Generalized Version Strings.
by tye (Sage) on Jul 26, 2001 at 09:44 UTC

    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):

    sub compare_versions { my( $left, $right )= map lc, @_; for( $left, $right ) { s/(\d+)/pack("n",length$1).$1/ge; } return $left cmp $right; }

            - tye (but my friends call me "Tye")
      I think yours does support differing number of digits in a part; e.g. 3.9 vs 3.10.

      As for error checking, which is larger: 3.2 or 3B or i3r2 ?

        Yes, it supports comparing versions were 3.10 comes after 3.9 (because 3.9==3.09), but it doesn't support decimal numbers where 3.10 comes before 3.9 (because 3.9==3.90) [but if the decimal numbers that will be compared together always have the same number of digits after the decimal (as is often the case), then it works]. Obviously it can't support both version strings and all decimal numbers, I just mentioned that because it is a general-purpose "natural sort".

        Well, I definitely consider 3B to be a revision to the base branch and so 3B comes after 3.2. But I supposed some may disagree with me. So rejecting such comparisons is a worthwhile feature that can't be duplicated by a simpler method. (:

                - tye (but my friends call me "Tye")

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://99832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-16 19:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found