Everybody has told you how to sort (college, then id), but nobody told you to USE STRICT!!! ;)

Now, some handy short-cuts in Perl programming:

Instead of using the ternery operator twice on each column for each row, you could just handle empty columns in the first check:

$student_name = (defined $row[1]) ? $row[1] : ' '; $student_blah = .... ad naseum
Or you could avoid all that extra typing by utilizing map:
while (my @row = $sth_report->fetchrow_array) { @row = map { $_ || ' ' } @row; # .... rest of code }
Also,the only variable you need is one to store the college (actually, you don't even need that one either! :D) ... the rest can be kept in @row, which can be then stored in a hash whose keys are the colleges, and whose values are the rows of the students (ordered by id) who belong to that college:
my %college; while (my @row = $sth_report->fetchrow_array) { @row = map { $_ || ' ' } @row; my $college = pop @row; push $college{$college}, [@row]; }
And some code to print it back out:
foreach my $college (keys %college) { print "$college:\n"; foreach my $row (@{$college{$college}}) { print "\t", join(', ', @$row),"\n"; } }
Hope this helps. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: Sorting data pullled in by DBI by jeffa
in thread Sorting data pulled in by DBI by data67

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.