in reply to Search engine code critique
This is the first thing that stands out. I am guessing that you want the ones with the most 'hits' first correct? Why not just use a simple sort. For example, I think this has the same functionality as the above code without me trying to figure out exactly what it was I was trying to accomplish a couple of months down the road (not that commenting it wouldn't help in this respect.)for ( my $i = scalar(@$results) - 1; $i >= 0; $i-- ){ for ( my $j = 1; $j <= $i; $j++){ if ( $$results[$j - 1]{'hits'} < $$results[$j]{'hits'} ){ my $temp = $$results[$j - 1]; $$results[$j - 1] = $$results[$j]; $$results[$j] = $temp; } } }
Even if you don't want to take it this far you can exchange these couple lines@$results = sort{ $b->{'hits'} <=> $a->{'hits'} } @$results;
withmy $temp = $$results[$j - 1]; $$results[$j - 1] = $$results[$j]; $$results[$j] = $temp;
which is similar to one of the first things i remember seeing in the camel (the swapping without a temporary variable thing.($$results[$j - 1], $$results[$j]) = ($$results[$j],$$results[$j - 1])
Though there might be more things this just stuck out at me as more a C type thing than a Perl type thing
-enlil
|
|---|