好需要你幫忙!!!!!!!
CIT coursework要用!!!!
sub parasort
{
my $sort = shift;
my $independent_array = shift;
my @dependent_arrays = @_;
my @sort_ix =
map unpack( 'N', substr( $_, -4 ) ),
sort
map &$sort( $independent_array->[ $_ ] ) . pack( 'N', $_ ),
0 .. $#$independent_array;
return map [ @{ $_ }[ @sort_ix ] ],
$independent_array,
@dependent_arrays ;
}
sub parasort (&@) {
my($coderef, $master_array, @arrayrefs) = @_;
my(%hash, @final);
@{$final[0]} = sort {&$coderef;} @{$master_array};
foreach my $m (0 .. $#{@{$master_array}}) {
foreach my $s (0 .. $#arrayrefs) {
push @{$hash{$$master_array[$m]}[$s];}, $arrayrefs[$s][$m]
+;
}
}
foreach my $m (sort {&$coderef;} keys %hash) {
$t = 1;
foreach my $s (@{$hash{$m};}) {
push @{$final[$t]}, @{$s};
++$t;
}
}
return @final;
}
my @array1 = (10, 9, 8, 7, 6, 5, 5, 3, 2, 1);
my @array2 = ( 3, 6, 2, 5, 6, 7, 8, 3, 2, 5);
my @array3 = ( 4, 6, 7, 4, 3, 2, 5, 7, 8, 9);
my ($array1, $array2, $array3) = parasort { $a <=> $b } \@array1, \@ar
+ray2, \@array3; #returns arrayrefs