JanLaloux has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sort messes up data
by McA (Priest) on Sep 08, 2014 at 09:06 UTC | |
by JanLaloux (Novice) on Sep 08, 2014 at 09:11 UTC | |
|
Re: sort messes up data
by Corion (Patriarch) on Sep 08, 2014 at 09:07 UTC | |
|
Re: sort messes up data
by Anonymous Monk on Sep 08, 2014 at 09:15 UTC |