The code seams right to me. ? If you sort by letters (e.g. by file type), mind to use cmp instead of <=> :
foreach (sort { $database{$a}[0] cmp $database{$b}[0]} @sample) {
And do not expect to sort great amounts of data by this; better use MySQL
for that.
And better sort pictures of your own children rather than pictures
of other men's women.
Regards, Detlef
