LPM: RE: "on break" processing in perl?
Janine
janine at emazing.com
Tue Jan 23 14:23:15 CST 2001
Regarding Dave's reporting woes, here's my solution. (In the real world I'd use fetchrow_array to populate %mdh, of course.)
Steve, your program was much more Perlish than mine. Thanks for posting it.
Janine
----------------------------------------
#!/usr/bin/perl -w
use strict; ## the brussel sprouts of Perl programming
my %mdh = (); ## mdh = MultiDimensional Hash
$mdh{'CS101'}{'1'}{'000-00-1111'} = 1;
$mdh{'CS101'}{'1'}{'000-00-2222'} = 1;
$mdh{'CS101'}{'1'}{'000-00-3333'} = 1;
$mdh{'CS101'}{'2'}{'000-00-4444'} = 1;
$mdh{'CS101'}{'2'}{'000-00-5555'} = 1;
$mdh{'CS117'}{'1'}{'000-00-1111'} = 1;
$mdh{'CS117'}{'1'}{'000-00-9999'} = 1;
my $course;
my $section;
my $ssn;
my $buf_ssn; ## temporary buffer for printing
my $buf_sec; ## another print buffer - need one for each level of grouping except the outmost
my $section_tot = 0;
my $course_tot = 0;
foreach $course (sort keys %mdh) {
print "Course $course: ";
$course_tot = 0;
$buf_sec = "";
foreach $section (sort keys %{$mdh{$course}}) {
$buf_sec .= "\tSection $section: ";
$section_tot = 0;
$buf_ssn = "";
foreach $ssn (sort keys %{$mdh{$course}{$section}}) {
$buf_ssn .= "\t\t$ssn\n";
$section_tot++;
}
$buf_sec .= "$section_tot students\n";
$buf_sec .= $buf_ssn;
$course_tot += $section_tot;
}
print "$course_tot students\n";
print $buf_sec;
}
More information about the Lexington-pm
mailing list