I am having an issue with some code I'm writing. I basically want to do the same process
for a list of course names (which are all under topic names). I pulled the course names into
a hash and the script works fine. The only problem is that there is no rhyme or reason to the order
that these courses print out. Ideally, I want them to be ordered by topic name AND course name, though
at this point, even having them ordered by topic name alone would be an achievement.
I am very, very new to Perl, and I just read somewhere that hashes have no concept of order. Do arrays?
I have just tried doing this in an erray, but am having problems with the foreach statement, I guess.
Does anyone know how I can order these using a hash? If not, can anyone tell me how to change this into
an array situation??
Here's the beginning of my code, up to the "foreach":
#!/usr/local/bin/perl5.005
use lib '../L2e/lib';
use DBI(0.90);
use strict;
use Database;
use CGI qw(:standard);
Database::->db_info_path("../L2e/lib/db.cfg");
my $dbh = new Database;
print "Content-type: text/html\n\n";
#Grab the evaluation responses from the form
my $tc9Questions = param('tc9Questions');
my $tcQ10 = param('tcQ10');
my $tcQ12 = param('tcQ12');
#Get the list of courses
my $title = "select C.il2e002_course_id_k, C.il2e002_course_title_x,
T.il2e001_topic_id_k from il2e001_topic T, il2e002_course C
where T.il2e001_topic_id_k = C.il2e001_topic_id_k order by T.il2e001_topic_desc_x,
C.il2e002_course_title_x";
my %titles = $dbh->fetch_all_hash($title);
foreach my $key (keys %titles)
{
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.