Thanks for all who helped with my Perl coding,
I thought some folks here might benefit from me posting the final
code I used on a current project:
---snip---
if ($sort_order == 1) {
# sort by name (front part of the key)
foreach my $key (sort {lc($a) cmp lc($b)} keys %index){
&print_table_rows($key);
}
}
elsif ($sort_order == 2) {
# sort by subject (values)
foreach my $key (sort { lc($index{$a}) cmp lc($index{$b}) } keys %index ) {
&print_table_rows($key);
}
}
else {
# sort by date and time (end part of the key)
foreach my $key (sort { my($A) = $a =~ /_(\d+)$/; my($B) = $b =~ /_(\d+)$/; $B <=> $A;
} (keys %index)) {
&print_table_rows($key);
}
}
sub print_table_rows {
my ($key) = @_;
# get the date and time
my ($year,$month,$day,$hours,$minutes,$seconds) = $key =~
/_(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
# remove the leading '0' for the hash %month
$month =~ s/^0//;
# get the name
($name = $key) =~ s/_\d+$//;
$name =~ tr/_/ /;
print <<data;
<tr bgcolor="#eeeecc">
<td><input type="checkbox" name="$key" onClick="CheckCheckAll();"></td>
<td><a href="data/$key.html">$index{$key}</a></td>
<td>$name</td><td>$month{$month} $day, $year $hours:$minutes:$seconds</td>
</tr>
data
}
*====================================================*
* Cora Connection Your West African Music Source *
* http://www.coraconnection.com/ *
* Resources, Recordings, Instruments & More! *
*====================================================*