I know you've already accepted an answer, and there are other really good
answers here, but I would propose something different: don't duplicate your
data. You only need to keep track of the arabic -> roman mapping once -- why
store what are essentially duplicate arrays of numbers, and sort every one?
Just sort the master list and look up the other values in a reference array as needed:
my @roman = qw(0 I II III IV V VI VII VIII IX X);
my @text = qw(zero one two three four five six seven eight nine ten);
my @values = (7, 2, 9);
my @sorted_values = sort @values;
my @sorted_roman = map { $roman[$_] } @sorted_values;
my @sorted_text = map { $text[$_] } @sorted_values;
use Data::Dumper;
print Dumper(\@sorted_values, \@sorted_roman, \@sorted_text);
prints:
$VAR1 = [
2,
7,
9
];
$VAR2 = [
'II',
'VII',
'IX'
];
$VAR3 = [
'two',
'seven',
'nine'
];
In a real environment, I would suggest using libraries to perform the
Roman and textual conversions for you:
use Roman;
my @sorted_roman = map { roman($_) } @sorted_values;
use Lingua::EN::Numbers 'num2en';
my @sorted_text = map { num2en($_) } @sorted_values;