Deans, Glenn (IT Solutions US) <> wrote:
> I'm trying to figure out the best way to sort version strings, like
> "2.13.87" (purely numerics for now), and found Sort::Versions at CPAN
> that seems to do what I want.  However, I can't find it listed in PPM
> or any other repository that I load.  I can download the pkg from
> CPAN but don't have a compiler installed on this box.  My head's been
> full of vbscript for the past year and trying to jump back to Perl
> and work out a method to sort these is a challenge.      

Well, its in the repositories that my ppm is pointing to. At least, I
have two entries for Sort::Versions and two repositories (activestate
and uwinnipeg - it would be nice if ppm told you which repository a
package was from). I am using version 5.10, BTW. You don't say which
version you are using.

If you really can't locate a ppm, then you shouldn't need a compiler to
install from CPAN, as it looks like a pure Perl package. You would only
need a make(-like) program. Your documentation should include a "Windows
Specific FAQ" which includes the question "Where do I get make for
Win32", in case you need any help with that.

> 
> Does anyone know where I can get this module or have a snippet of how
> to go about sorting version strings? 

Other than using said module, a fairly simplistic method of sorting
version string that you subscribe might be:

use strict;
use warnings;

sub vcomp {
    my @v1 = split /\./, $a;
    my @v2 = split /\./, $b;
    while (@v1 and @v2) {
        my $p1 = shift @v1;
        my $p2 = shift @v2;
        return $p1 <=> $p2 if $p1 <=> $p2;
    }
    return @v1 <=> @v2;
}

my @array = qw{3.5.6 2.18.27 3.5.7 3.5 1.1.1};
print "$_\n" for sort vcomp @array;
 

HTH

-- 
Brian Raven 

-----------------------------------------------------------------------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to