One Subroutine Replaces Two

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

It's the argument which I pass to the subroutine that makes the difference.

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

versus

  foreach my $period (@overall) {
      my ($sch, $occ, $percent) = _calculate_row( \%{$period} );

Previous Back to start of show Next
Slide: 10 calculate_row © 2003 James E. Keenan