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

Jay Hannah jay at jays.net
Sun Mar 15 12:41:31 PDT 2009


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;
    }
}




More information about the Omaha-pm mailing list