in reply to Seek Help Refactoring

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.

Replies are listed 'Best First'.
Re^2: Seek Help Refactoring
by jkeenan1 (Deacon) on Apr 03, 2006 at 00:49 UTC
    xdg wrote:

    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?

    No, it is not. Some of the variables that go into the conditional are more tightly scoped than that or not even declared yet. So I can't pass a pre-computed argument.

    jimk