After Staring at This for Several Months ...

I decided to focus just on the data for just one group for just one week: %{$week{$_}}. Its value is a hash which may have keys titled 'scheduled', 'occurred', and/or 'excused'.

I pass a reference to that hash's value to a subroutine.

  sub _calculate_group_week {
    my $v = shift;
    my %group_week = %{$v};
    my ($sch, $occ, $percent);
    $sch     = defined ($group_week{'sched'}) ? $group_week{'sched'} : 0;
    $occ     = defined ($group_week{'occur'}) ? $group_week{'occur'} : 0;
    $percent = $sch                           ? $occ / $sch * 100    : 0;
    return ($sch, $occ, $percent);
  }

The top part of the original subroutine now looked like this:

  foreach my $period (@overall) {
    my %week = %{$period};
    foreach (keys %week) {
      my ($sch, $occ, $percent) = _calculate_group_week(\%{$week{$_}});

Previous Back to start of show Next
Slide: 7 after_staring © 2003 James E. Keenan