Hi all,

Is there an easy way to sort 2 arrays and keep the relating indices together.
for instance I have an array of times, and an array of emails.
I would like to give the user a choice of sorting by time(numeral) or 
email(alpabetical);

[EMAIL PROTECTED] = ();
for(my$i=0;$i<@open_pages;$i++){
  my$time = -M "../open_pages/$_";
  push(@time, $time);

#this code is just for a readable time description, 
  my$lastchange ="";
  if($time>1){s/\.\d*//;if($time>1){$lastchange = "$time 
days";}else{$lastchange = "$time day";}}
  if($time<1){$time  = $time*24;if($time>
=2){if(/\.\d*/){s/\.\d*//;}$lastchange = "$time hours";}else{$time  = 
$time*60;if(/\.\d/){s/\.\d*//}$lastchange = 
"$time minutes";}}
   $lastchange =~ s/\..*\d(.*)/$1/;

  push(@Cemails, $Cemail);

  my$row = qq{<TR><TD align="center">$Cemail</TD><TD align="center">
$lastchange</TD><TD align="center"><A class="main_LNK"  
href="./view_page.pl?fl=$Cemail&
st=oo">view</A></TD></TR>};

#  @rows is the array I want to rearrange 
 push(@rows,$rows});
}

# here I would  like to sort @rows according to the method they chose
# but I'm not sure how to sort 2 arrays at the same time without using some 
sort of grep for the indices.

[EMAIL PROTECTED] = ();
if($q->param('oldest') || $q->param('newest')){
  @sorted = sort($a<=>$b) @times;
  # change @rows here somehow with @times
  if($q->param('oldest))[EMAIL PROTECTED] = reverse @sorted;}
}

elsif($q->param('AtoZ') || $q->param('ZtoA')){
  @sorted = sort($a cmp $b) @Cemails;
  # change @rows here somehow with @Cemails
  if($q->param('ZtoA'))[EMAIL PROTECTED] reverse @rows}
}



Hope this is understandable to everyone,
Thanks

Reply via email to