Good afternoon, TGIF! Sorry to say that lot of this still above my head, but I am trying, and I am getting better.... <http://dowda.rockin.net:31822/cgi/forum_idx.pl?3> My code has problems, first one is line: ($hours,$minutes,$seconds,$month,$day,$year) = $key =~ /_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/; is repeated all over the place, which I believe is not a good thing, But more to the point is making the sorting correct and the code more concise; Ignoring the second branch of the code below, the final branch (the else) does kind sort, it puts the 'dates' in the correct order, but seems to neglect time each key (which is really a file name, just add .html) is: dave_1132376152001 Is this possible: $date_time = "$month{$month} $day, $year $hours:$minutes:$seconds"; if ($sort_order == 1) { # sort by name # $key is really the filename with out the path and '.html' foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){ my ($name,$hours,$minutes,$seconds,$day,$month,$year); ($hours,$minutes,$seconds,$month,$day,$year) = $key =~ /_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/; $month =~ s/^0//; #$date_time will get interpolated twice, "$month{$month} $day, $year $hours:$minutes:$seconds"; &print_table_rows($key,$subjects{$key},$date_time); # &print_table_rows($key,$subjects{$key},"$month{$month} $day, $year $hours:$minutes:$seconds"); } } elsif ($sort_order == 2) { # does not work at this time # sort by subject # foreach my $subject (sort {lc($a->[1] cmp lc($b->[1]} map {[ $_, $subjects{$_}]}) { # $subjects{$subject->[0]}, $subject->[0]; # foreach my $key (sort {lc($a) cmp lc($b)} keys %subjects){ # my ($name,$hours,$minutes,$seconds,$day,$month,$year); # ($hours,$minutes,$seconds,$month,$day,$year) = /_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/; # &print_table_rows($_,$subject,"$month{$month} $day, $year $hours:$minutes:$seconds"); } } else { # sort by date and time #$sortValue = "$name$hours$minutes$seconds$day$month$year"; foreach my $key (sort { my($A) = $a =~ /_(\d+)$/; my($B) = $b =~ /_(\d+)$/; $A <=> $B; } (keys %subjects)) { my ($hours,$minutes,$seconds,$day,$month,$year); ($hours,$minutes,$seconds,$month,$day,$year) = $key =~ /_(\d{2})(\d{2})(\d{2})(\d{1,2})(\d{2})(\d{4})/; # ($name) = $key =~ /(\w+_?)+_/; $month =~ s/^0//; # remove after debug &print_table_rows($key,$subjects{$key},"$month{$month} $day, $year $hours:$minutes:$seconds"); } } print "</table></form>\n"; print &html_end; sub print_table_rows { my ($fileName, $subject, $date) = @_; ($name = $fileName) =~ s/_\d+$//; $name =~ tr/_/ /; print <<data; <tr bgcolor="#eeeecc"> <td><input type="checkbox" name="$fileName" onClick="CheckCheckAll();"></td> <td><a href="data/$fileName.html">$subject</a></td> <td>$name</td><td>$date</td> </tr> data } ---------- From: Wagner-David Sorry, but as soon as I saw the input coming back I knew it was really untested. Should be sort {lc($a->[1]) cmp lc($b->[1])} and NOT sort {lc($a) cmp lc($b)} Wags ;) -----Original Message----- Sent: Thursday, June 14, 2001 13:21 To: 'David Gilden'; [EMAIL PROTECTED] Subject: RE: Sort hash by values Use of keys, map and sort (untested) foreach my $subject (sort {lc($a) cmp lc($b)} map {[ $_, $subjects{$_}]} keys %subjects){ printf "%-40s: %-s\n", $subjects{$subject->[0]}, $subject->[0]; } From: Timothy Kimball my (%idToName); foreach ( @lines ) { my ($id,$name) = /^(...)..(.{8})/g; next if $name eq "xx "; $idToName{$id} = $name; } Also, instead of prepending the sort key to each line, try making it the value of a hash, which has the line itself as the key. Something like this: my (%sortKeys); foreach ( @lines ) { my $sortKey = ... # do something to create the sort key, # using %idToName to map the ID to the name $sortKeys{$_} = $sortKey; } Then create a sub to pass to sort: sub bySortKey { $sortKey{$a} cmp $sortKey{$b} } -------------------------------------------- Looking for Web Talent, You found it! portfolio: www.coraconnection.com/web/ email: [EMAIL PROTECTED] tel/fax: (860) 231-9988 --------------------------------------------