You imply, but don't say explicitly, that all your arrays are the same size. Is this correct? Assuming it is, you have something like:
And you want to be able to sort all of them together, based on one of them -- bringing the even numbers to the front, say?@numbers = (1,2,3,4,5,6,7); @words = ('one', 'two', 'three', 'four', 'five', 'six', 'seven'); @odd_even = ('odd', 'even', 'odd', 'even', 'odd', 'even', 'odd'); @prime = ('not', 'prime', 'prime', 'not', 'prime', 'not', 'prime');
Have you considered an array of arrays?
@numbers_with_attributes = ( [1, 'one', 'odd', 'not'], [2, 'two', 'even', 'prime'], [3, 'three', 'odd', 'prime'], [4, 'four', 'even', 'not'], [5, 'five', 'odd', 'prime'], [6, 'six', 'even', 'not'], [7, 'seven', 'odd', 'prime'], ); @alpha_sort = sort { $a[1] cmp $b[1] } @numbers_with_attributes;
In reply to Re: Remembering original order of an array
by menolly
in thread Remembering original order of an array
by seaver
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |