Folks,

Sorry about the earlier post,
perhaps another newbie might get some benefit from this posting :) 
Here is part of the revised code without the if{} block.

To see the exercise I have been working on point your browser to:
http://dowda.rockin.net/cgi/sql_sort3.pl

It does point another issue if two 'people' have same the birthday,
how do handle sorting the names!!!!!


Dave

---new----
.....other code deleted....


elsif ($sort_by == 1){
# sort by first name
&sort_name('first_name','last_name',);
} 

elsif ($sort_by == 2){
# sort by last name
# &sort_name('last_name');
&sort_name('last_name','first_name',);
}


elsif ($sort_by == 3){
# sort by birthday
&sort_num('birthday');
}


elsif ($sort_by == 4){
# sort by Sex
&sort_name('sex');
}


sub sort_name() {
my ($first_field,$second_field) =@_;

foreach my $key (sort 
{ 

 ($A) = $database{$a}{$first_field}; 
 ($B) = $database{$b}{$first_field};
 ($C) = $database{$a}{$second_field}; 
 ($D) = $database{$b}{$second_field};

(!$sort_direction) ? (lc($A) cmp lc($B) || lc($C) cmp lc($D)) : (lc($B) cmp lc($A) || 
lc($D) cmp lc($C));
} keys %database){
&print_tableData($key);
    }
}


----old----
.....other code deleted....

elsif ($sort_by == 1){
# sort by first name
&sort_name('first');
} 

elsif ($sort_by == 2){
# sort by last name
# &sort_name('last_name');
&sort_name('last');
}

elsif ($sort_by == 4){
# sort by Sex
&sort_name('sex');
}


sub sort_name() {

my ($A,$B,$C,$D,$which);
($which) = @_;


foreach my $key (sort 
{ 

if ($which eq 'last') # sort last names
{
 ($A) = $database{$a}{last_name}; 
 ($B) = $database{$b}{last_name};
 ($C) = $database{$a}{first_name}; 
 ($D) = $database{$b}{first_name};
 }
 elsif ($which eq 'first') # sort first names
 {
($A) = $database{$a}{first_name}; 
($B) = $database{$b}{first_name};
($C) = $database{$a}{last_name}; 
($D) = $database{$b}{last_name};

} else {

 ($A) = $database{$a}{sex}; 
 ($B) = $database{$b}{sex};
}

*====================================================*
*   Cora Connection Your West African Music Source   *  
*   http://www.coraconnection.com/                   *  
*   Resources, Recordings, Instruments & More!       *
*====================================================*

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to