One question I'd have is if you need to maintain the initial ordering. If you don't, you could build some sort of Schwartzian transform and move the cross-array slices around that way.
A deeper question would be if parallel arrays are really what you want to do. Anytime I see parallel arrays, especially in Perl, I start itching to offer up possible better solutions. For example, you have a record. Whenever I hear "record", I immediately think "hash". They're built for storing records. Then, you have a list of hashrefs for your various records. If you need to print out all of a given field, then iterate over the array.
The reason I suggest this is that sorting this list of hashrefs becomes trivial.
And, double-entries are automatically taken care of. Plus, you can now do multi-level sorts. Sort on state, then town, or whatever.@sorted_list = sort {$a->{Field} <=> $b->{Field} || $a->{Field} cmp $b->{Field}} @unsorted_list
In reply to Re: Sorting arrays and maintaining an index
by satchboost
in thread Sorting arrays and maintaining an index
by Prince99
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |