Is the conditional known before the if-else logic? If so, why not just pass them as a precomputed argument rather than as a closure?
sub alpha { my $self = shift; my $condition = 1; # always return $self->_internal_sub($condition); } sub beta { my $self = shift; my $gamma = get_gamma_somewhere(); my $condition = $self->{baz} eq $gamma; return $self->_internal_sub($condition); } sub _internal_sub { my $self = shift; my $condition = shift; ... foreach ... if ... if ... if ... push @foo, [ @bar ] if $condition; } } } else { push @foo, [ @bar ] if $condition; } } push @foo, [ @bar ] if $condition; return \@foo; }
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
In reply to Re: Seek Help Refactoring
by xdg
in thread Seek Help Refactoring
by jkeenan1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |