[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] "order by begin, end"




In SQL I could accomplish this with "order by begin, end".

But in my Perl nested data structure these things take more typing.  :)

SQL++   :)

j




   foreach my $result (sort by_begin @ordered) {
      printf("   %s..%s %s\n",
         $result->{hit_position}->{begin},
         $result->{hit_position}->{end},
         $result->{small_seq}->{seq}
      );
   }


sub by_begin {
   if ($a->{hit_position}->{begin} > $b->{hit_position}->{begin}) {
      return 1;
} elsif ($a->{hit_position}->{begin} == $b->{hit_position}-> {begin}) {
      if ($a->{hit_position}->{end} > $b->{hit_position}->{end}) {
         return 1;
} elsif ($a->{hit_position}->{end} == $b->{hit_position}-> {end}) {
         return 0;
      } else {
         return -1;
      }
} elsif ($a->{hit_position}->{begin} < $b->{hit_position}-> {begin}) {
      return -1;
   }
}