in reply to Order a hash?
You choice then is to sort the keys of the hash. You foreach loop ( which I write as a for loop - they are identical, so do not be confused ) would look something like:
which will sort the keys in asciibetical order. To sort the keys on some criteria other than asciibetical, try something like this ( I hope I remember how fetch_all_hash works ):for my $key ( sort keys %title ) {
# This will sort by title, then by topic id sub by_course_and_title { return $title{$a}{il2e002_course_title_x} cmp title{$b}{il2e002_cour +se_title_x} || $title{$a}{il2e002_topic_id_k} cmp title{$b}{il2e002_topic_id +_k}; } for my $key ( sort &by_course_and_title keys %title ) {
In answer to your other question, how to step through an array, it is simply
See perldoc -f sort to understand a bit more of the possibilities of the sort command - it is quite potent.for my $foo ( @foo ) { # Do something interesting }
|
|---|