Afficher un message
Vieux 30/03/2008, 03h45   #16
Tony De
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: on best way to gather/sort results ?

Todd Benson wrote:
> On Sat, Mar 29, 2008 at 1:55 AM, Tony De <tonydema@gmail.com> wrote:
>>
>> Oooooooo! We'll that makes perfect sense. Thanks! You know, sometimes
>> you read your handy pickaxe or a blog somewhere, buy it slides right
>> past you. I appreciate the clarification.
>>
>> tonyd

>
> They all work. I use #sort_by all the time for legibility, and I
> don't care that much about speed for the stuff I work on. According
> to the docs, sort_by doesn't scale by speed for small key sets and
> large populations (that might be your case). It does, however,
> perform better when there occurs object creation for the comparison
> test.
>
> Todd


Thanks Jesus & Todd for your posts also. I appreciate the education.
Forums are great for getting real world experience on language usage and
gotcha's. So I do have another question on my sort. I realize that in
addition to the sort on the second element in each row of my array
(sourceip) I would also like to then sort on the third element (email).
So my current sort is:

@results.sort! {|x, y| y[1] <=> x[1]}

So this now sorts first by element[2] and then by element[3]:
new_results = @results.sort_by { |x| [x[1], x[2]] }

There are so many ways to accomplish the same result. That dosen't
mean, however, it's the most efficient. Would there be a more efficient
way to do this? Not that this script is costing me a great deal in
resources. But it nice to code tight when possible. Thanks again.

tonyd


--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
 
Page generated in 0,07463 seconds with 9 queries