in reply to Seek Help Refactoring

My first step would be to reduce the nesting. Each level of if nesting is another and clause the reader of the code has to remember to understand the condition that gets a particular line of code executed.

Often nested ifs can tidy up a lot if you use early exits or negate the condition. Sometimes a redundant test cleans up the nesting sufficiently that the time cost doesn't matter compared to the ease of understanding. Sometimes it's even worth using a exitable if:

while (condition) { # Exitable if if (condition) { ... last; #early exit } .... last; # Bad things happen if this if omitted :) }

Asside from that you could simply pass a boolen rather than a coderef. Then the test becomes push @foo, [ @bar ] if $doTest and $self->{baz} eq $gamma;.


DWIM is Perl's answer to Gödel