in reply to sort != sort
WRT replicating it: I also tried prior to the post and cannot, I was hoping there might be an obtuse reason someone is aware of, since I am positive about the data, etc. Ie, this is not a coding error. Here's exactly the way I am verifying the issue right now:
if ($#Terms > 0) { print "HERE\n"; # to confirm this takes place; @Notes = sort { $b->{terms} <=> $a->{terms} } @Notes; } my @Sorted = sort { $b->{terms} <=> $a->{terms} } @Notes; print "$#Notes $#Sorted\n"; for (my $i = 0; $i<=$#Notes; $i++) { print $Notes[$i]->{terms}.$Sorted[$i]->{terms}."\n"; }
The output begins:
HERE 1008 1008 12 12 12 12 12 [..etc: nb, there is never anything other than 1 or 2]
As if "@Notes" were scoped locally in the if block. Again, this not normal behaviour nor can I replicate it in a simpler script. However, I do not see possibility of bad data affecting the above logic (please tell me specifically how you think it could, if you do). These are two versions of the same sort operation on the same array.
Interestingly, if I make a single change, by moving "my @Sorted = sort" to before the if block instead of after it (making it the first line in the above code) both arrays are the same.
I've done this and other tests numerous times here purely for this purpose, there is no possibility of me having "forgotten a change in the middle". But I'm a sceptic too: if you think this is impossible and I'm lying, I don't blame you ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sort != sort
by Corion (Patriarch) on Oct 25, 2010 at 17:28 UTC | |
by halfcountplus (Hermit) on Oct 25, 2010 at 18:00 UTC | |
by Corion (Patriarch) on Oct 25, 2010 at 18:03 UTC | |
by halfcountplus (Hermit) on Oct 25, 2010 at 18:33 UTC | |
by Corion (Patriarch) on Oct 25, 2010 at 18:41 UTC | |
|