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:
Or you could avoid all that extra typing by utilizing map:$student_name = (defined $row[1]) ? $row[1] : ' '; $student_blah = .... ad naseum
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:while (my @row = $sth_report->fetchrow_array) { @row = map { $_ || ' ' } @row; # .... rest of code }
And some code to print it back out:my %college; while (my @row = $sth_report->fetchrow_array) { @row = map { $_ || ' ' } @row; my $college = pop @row; push $college{$college}, [@row]; }
Hope this helps. :)foreach my $college (keys %college) { print "$college:\n"; foreach my $row (@{$college{$college}}) { print "\t", join(', ', @$row),"\n"; } }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |