in reply to Re^7: sort != sort
in thread sort != sort

So, where in the code you've shown do you sort the things?

Likely, there is some place where you either sort the wrong thing, sort by the wrong column or assign the result to the wrong thing (a global variable instead of a lexical variable or the other way around). But to determine that, we'll need to see the code as a (small) whole instead of as a collection of selected excerpts.

Replies are listed 'Best First'.
Re^9: sort != sort
by halfcountplus (Hermit) on Oct 25, 2010 at 19:31 UTC
    The only sort that happens is the one I've shown you, on the array constructed above (notice the array name, @Notes). There is nothing else to it. You have 100% of the code in which @Notes is referenced here, and 100% of the code which constructed it. If anyone wants to take the time to look for errors, I'm of course grateful. Just to be extra clear:
    1. @Notes is constructed using the code and package above.
    2. @Notes is sorted using the code shown earlier.
    3. Sorted array is displayed making use of PNSearch::highlight, but this is subsequent to everything else; in fact I've been logging this with "die" right after the sort. Without that die all the notes do appear correctly, by which point the data has passed through more than a few error checks. As I said, none of those if (!defined) fire, I'm logging warnings and making them fatal, use strict, use Taint, not a peep. Numbers compare to numbers, strings are not mixed up, mangled, or foreshortened etc, etc. On visual inspection all the search finds and highlights are also correct.

    Maybe also worth mentioning this is a revision (new features) of code I wrote last year that has been used on a production server daily since then. So it's already gone thru a lot of tweaking, testing, usage/error logging, and debugging. I've been asked to implement this elsewhere, and I've never received any complaints.

      halfcountplus,

      Here's my two cents. Please consider the following:

      1. The various sort functions are well-known and I doubt the built-in sort has a new bug.

      2. Even if the built-in sort is somehow broken, you said you used a couple of other sorts, as well, and I doubt they all broke at once.

      3. When you feed sort a block, as below,
        @Notes = sort { $b->{terms} <=> $a->{terms} } @Notes;
        you're comparing number to number (<=>), or text to text (cmp). It returns a -1, 0, or 1. Constructions like the one above are VERY common and work in the general case. You've made an assumption that @Notes is not being assigned to, but if the comparison operators are working, and the sort functions are working, and the assign-to operator is working, then the only thing left is to look at what's actually being compared.

      4. Which, I hasten to point out, is the one thing we haven't seen yet except as a small excerpt of dumped hashes. We can't duplicate all your code because we don't have all your modules or your databases, and all you are showing us is your code and part of your databases. Please use Data::Dumper or YAML or whatever you like and Dump the the actual structure of @Notes and post at least a subset. Maybe here:
        foreach my $l (@lines) { my $pns = PNSearch->new($MUH, $l->[0]-$cur, $l->[1], $file); push @Notes, $pns if ($pns); $cur = $l->[0]; } close($MUH); } use Data::Dumper; open DUMP, ">somefile.txt" or die $!; Dumper \@Notes; close DUMP;
      5. No one has called you a liar, and it doesn't have to be a bug in your code (which you said you updated, by the by!!!), but obviously something isn't working and that's why people keep asking to see what's actually in @Notes, rather than hear your assurances about it.

      Sincerely,

      --marmot