Using a hash works as already mentioned. For completeness, you should also know another standard trick. You can sort a list of indices:
This trick can be useful for speeding up a lengthy sort operation. It is also a great way to keep one or more lists sorted in more than one order at once. - tyemy @urls= qw( yahoo.com ebay.com google.com ); my @links= qw( yahoo ebay google ); my @idx= sort { $urls[$a] cmp $urls[$b] } 0..$#urls; # Now @urls[@idx] is sorted # and @links[@idx] is in the same order. # You could loop in that order like so: for my $i ( @idx ) { print "$urls[$i]\t$links[$i]\n"; } # Or you could just sort the arrays in place: @urls= @urls[@idx]; @links= @links[@idx];
In reply to Re: Sorting issues (indices)
by tye
in thread Sorting issues
by toonski
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |