in reply to Simplifying a nest of if statements
I think that a table-driven approach might make the logic of what you're doing more evident:
my @cases = ( { osname => 'INTIM', total => { duration => \$ototalintimdur, counter => \$ototalintimcdr. }, freecall => { duration => \$ointimfreedur, counter => \$ointimfreecdr. }, voicemail => { duration => \$ointimvoicedur, counter => \$ointimvoicecdr. }, }, { osname => 'TOUCH', total => { duration => \$ototaltouchdur, counter => \$ototaltouchcdr. }, freecall => { duration => \$otouchfreedur, counter => \$ototaltouchcdr. }, voicemail => { duration => \$otouchvoicedur, counter => \$otouchvoicecdr. }, }, ) if ( defined $osname{$num1} ) { foreach my $case ( @cases ) { next unless $osname{$num1} =~ /$case->{osname}/; my $calltype = ( defined $freecall{$bnum} ) ? 'freecall' : ( defined $voicemail{$bnum} ) ? 'voicemail' : undef; my @counter_sets = map $case->{$_}, grep $_, 'total', $calltype; foreach my $counters ( @counter_sets ) { ${ $counters->{duration} } += $dur; ${ $counters->{counter} } ++; } last; } }
|
|---|