> -----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.
<=> should probably still work, because when evaluating a string as a number, Perl will evaluate up to the first character that doesn't look like part of a number. so "1234 x5" evalutates as the number 1234 (stops at the space char). If the number you want to sort by is not at the beginning of the string (leading blanks are OK), you have to write a more elaborate comparison routine. Have you tried just using <=>? If it doesn't work for you, post a specific example that illustrates the problem. > Sorry if this is a dumb question. Nah, it's a good question. Anyway, we get spanked if we even look sideways at somebody (speaking as one who's been spanked) :~) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]