Dear Monks, I have a list of references to "records" that has to be sorted based on one of the fields of the record. I use the following sort code (in the example I use records with only one field):
use strict; my $rRecord; my @List; my @SortedList; $rRecord = [12]; push(@List, $rRecord); $rRecord = [3]; push(@List, $rRecord); $rRecord = [9]; push(@List, $rRecord); $rRecord = [1]; push(@List, $rRecord); @SortedList = sort { $List[$a][0] <=> $List[$b][0] } @List; my $Print = ''; for( my $i = 0; $i <= $#SortedList; $i++ ) { $Print .= " $SortedList[$i][0]"; } print "$Print\n";
After executing the sort the data gets messed up, the debugger looses track of it. In my real code it works the first time but executing the same sort twice in a row the debugger hangs on the second sort. Clearly something is wrong but I can't figure it out.
In reply to sort messes up data by JanLaloux
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |