<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content=1 name=qrichtext>
<STYLE type=text/css>P {
        
}
LI {
        
}
</STYLE>
<META content="MSHTML 6.00.6000.16825" name=GENERATOR></HEAD>
<BODY
style="FONT-WEIGHT: 400; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-FAMILY: 'DejaVu Sans'"
bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Without a real description of the problem, here
is my attempt. I used a simple scalar representation of data
instead of a tree. </FONT><FONT face=Arial size=2>If someone would care to
do a time comparison, I would be curious to see the results.</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>#!/usr/bin/perl</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>use strict;<BR>use warnings;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>my @list = (<BR>
"1.3",<BR> "1.2.3",<BR>
"1.2.3.1",<BR> "1.2.4.1",<BR>
"1.2.30",<BR> "1",<BR> "1.2",<BR>);<BR># The
expected sort order is the same as the order above</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2>sub byoid<BR>{<BR> # convert dot seperated
oid digits into a packed character string<BR> # suitable for string
comparison, e.g. '65.66.67' => 'ABC'<BR> my $x;<BR> $x .=
pack('C', $_) foreach (split(/\./, $a));<BR> my $y; $y .= pack('C',
$_) foreach (split(/\./, $b));<BR> return ($x cmp $y);<BR>}</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>my @sorted = sort byoid @list;<BR>print "Sorted
list:\n", join("\n", @sorted), "\n";</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2>sub
byoid_slower_more_readable_version<BR>{<BR> # convert dot seperated oid
digits into digits with leading 0's<BR> # suitable for string comparison,
e.g. '1.2.3' => '001002003'<BR> my $x;</FONT></DIV>
<DIV><FONT face=Arial size=2> </FONT><FONT face=Arial size=2>$x .=
sprintf('%03d', $_) foreach (split(/\./, $a));<BR> my $y;</FONT></DIV>
<DIV><FONT face=Arial size=2> $y .= sprintf('%03d', $_) foreach
(split(/\./, $b));<BR> return ($x cmp $y);<BR>}<BR></DIV></FONT>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT
face=Arial size=2></FONT><FONT face=Arial size=2></FONT><FONT face=Arial
size=2></FONT><FONT face=Arial size=2></FONT><BR>Indy Singh<BR>IndigoSTAR
Software -- <A href="http://www.indigostar.com">www.indigostar.com</A></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=Henry.Baragar@instantiated.ca
href="mailto:Henry.Baragar@instantiated.ca">Henry Baragar</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=tpm@to.pm.org
href="mailto:tpm@to.pm.org">Toronto Perl Mongers</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, May 01, 2009 2:46 PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [tpm] OID sorting</DIV>
<DIV><FONT face=Arial size=2></FONT><BR></DIV>Hello,<BR>
<P
style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-paragraph-type: empty; -qt-block-indent: 0; -qt-user-state: 0"><FONT
face=Arial size=2></FONT><BR></P>There were a couple of suggestions for Fulko
about how to improve his sorting of OID's (strings of the form
^\d+([.]\d+)*$). Attached is my suggestion for rebuilding the tree and walking
the tree. I would be curious to see how this solution compares to the other
solutions, both in terms of readability and performance.<BR>
<P
style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-paragraph-type: empty; -qt-block-indent: 0; -qt-user-state: 0"><BR></P>Regards,<BR>Henry<BR>
<P
style="MARGIN: 0px; TEXT-INDENT: 0px; -qt-paragraph-type: empty; -qt-block-indent: 0; -qt-user-state: 0"><BR></P><BR>--
<BR><BR>Henry Baragar<BR>Instantiated Software<BR>416-907-8454 x42
<P></P>
<P>
<HR>
<P></P>_______________________________________________<BR>toronto-pm mailing
list<BR>toronto-pm@pm.org<BR>http://mail.pm.org/mailman/listinfo/toronto-pm<BR></BLOCKQUOTE></BODY></HTML>