not a dumb question... I actually have the same problem. I have version numbers that look like this:
V1.2.3 V1.2.20 V1.2.23 and it sorts it wrong with cmp and <=> soo.. I had to come up with my own sort subroutine here is very generic one that breaks up the elements by \w (word types [a-Z0-9]) that I made and works like a champion. to use it: use strict; use warnings; my @sorted = sort { wordtype() } @your_array; # for reverse my @sorted = sort { wordtype($b, $a) } @your_array; sub wordtype { # # Inputs: $a, $b (not required) # # Globals: $a $b # # Subs called: NONE # # Purpose: sort \w chars in groups # numerically if numbers # # Returns: sort ordering (1,0,-1) # my ($a, $b); if(exists $_[0]){ $a = $_[0]; } else { no strict 'refs'; $a = ${caller()."::a"}; } if(exists $_[1]){ $b = $_[1]; } else { no strict 'refs'; $b = ${caller()."::b"}; } my @first = split /\W/, $a; my @second = split /\W/, $b; for(my $n = 0; $n <= $#first; $n++){ if($first[$n] =~ /^\d+$/ && $second[$n] =~ /^\d+$/){ return $first[$n] <=> $second[$n] if $first[$n] <=> $second[$n]; } else { return $first[$n] cmp $second[$n] if $first[$n] cmp $second[$n]; } } return 0; } ################################################## END wordtype > -----Original Message----- > From: nkuipers [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, July 24, 2002 1:39 PM > To: [EMAIL PROTECTED] > Subject: another sort question (flame away) > > > Hello all, > > My hash keys look something like this: > > >1234 x5 > > So I am thinking a cmp, as opposed to <=> is best. > > What I want is for the keys to be sorted as follows: > > >1 x.... > >2 x.... > >3 x.... > .. > .. > .. > >n x.... > > This is what I have in my script at the moment: > > my @sort_this = keys %final_list; > my @sorted = sort { $a cmp $b } @sort_this; > for (@sorted) { print OUT "$_\n$final_list{$_}\n" } > > This gives > > >1 x.... > >10 x.... > >100 x.... > >1000 x.... > >1001 x.... > > etc. > > Any suggestions? I'm not asking for you to spell it out for > me with code and > all unless you really want to. Sorry if this is a dumb question. > > cheers, > > nathanael > > "I think for my lunch tomorrow I'll make a tuna and pickle > triangle bunwich." > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > ---------------------------------------------------------------------------- -------------------- The views and opinions expressed in this email message are the sender's own, and do not necessarily represent the views and opinions of Summit Systems Inc. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]