http://www.perlmonks.org?node_id=368279

bradcathey has asked for the wisdom of the Perl Monks concerning the following question:

Fellow Monks,

My program calls a large (200 lines) internal subroutine about 1/3 of the time the script is run. The subroutine requires 4 arguments to run and returns a AoH ref for output to HTML::Template. To complicate matters, it calls other sub routines (5 and 10 liners that are only needed by that large sub) to perform basic formatting tasks, etc. So, things currently look like:

#!/usr/bin/perl use strict; ...etc... ...initiate variables... ...HTML::Template setup... my $AoH = &largesub($a, $b, $c, $d) if $run_large_sub; $template -> param( todisplay => $AoH ); print $template->output(); exit(); sub largesub { my ($e, $f, $g, $h) = @_; my $foo = &smallsub($e); ...process... return \@AoH; } sub smallsub { ...process... }

Questions: 1) do I leave it as is? (seems messy) 2) do I spin off the large sub and it supporting subs as a module? (modules always get loaded) 3) do I use Selfloader to avoid loading all those subs? (subs stay in main script, but don't always get loaded) 4) What is the cleanest, most efficient, most readable solution? Thanks!


—Brad
"Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton