Sorting version strings

Sorting version strings

am 10.12.2008 16:30:07 von Glenn.Deans

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.

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

.................................
Kind regards

Glenn Deans
Architect
Siemens IT Solutions and Services
Urbana, OH USA
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Sorting version strings

am 10.12.2008 17:23:54 von Brian Raven

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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Sorting version strings

am 10.12.2008 18:11:30 von Gisle Aas

On Dec 10, 2008, at 8:23 , Brian Raven wrote:

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

From the command line run 'ppm desc ' to see what repository a
package comes from. If your search only return a single match that's
the form you will see directly.

From the PPM GUI you can view the repo by selecting "View > View
Columns > Repo". This menu is also available by right-clicking on the
column headers.

--Gisle

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Sorting version strings

am 10.12.2008 18:16:31 von Brian Raven

Gisle Aas wrote:
> On Dec 10, 2008, at 8:23 , Brian Raven wrote:
>
>> 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).
>
> From the command line run 'ppm desc ' to see what repository a
> package comes from. If your search only return a single match that's
> the form you will see directly.
>
> From the PPM GUI you can view the repo by selecting "View > View
> Columns > Repo". This menu is also available by right-clicking on
> the column headers.

Excellent. Thanks. Which means that I can now confirm that
Sort::Versions is in the Activestate and uwinnipeg repositories for
5.10, rather than just guessing.

--
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
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Sorting version strings

am 12.12.2008 17:27:58 von Glenn.Deans

Sorry it took so long to get back to you, but thank you all for the
help. Bill's snippet works great, but makes me realize I'm not that
knowledgeable on how <=> works and therefore where to use it. The camel
book is a little light on it so I'll have to experiment w/it and try to
work it out by trial & error. At least now I can quickly get counts of
my systems using the version of various items from Active Directory or
the system itself; OS, Office, AV pattern, OemDuplicatorString, etc.

As for the module, I'm working off a new XP build and running 5.10.0
build 1004. Now the PPM GUI does not show or find Sort-Versions even
though I have the 5.10 repos for ActiveState & uwinnipeg installed. Now
if I use ppm-shell and run the search from the command line, 2 hits - no
problem. So I'm not really sure what the difference is, but I'll stick
with the command line since it seems to be more reliable.

Thanks again for the assistance.

.................................
Kind regards

Glenn Deans
Architect
Siemens IT Solutions and Services
Urbana, OH USA
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs