C
ccc31807
I have an application (the same one that my last few posts have
concerned) that is growing rather large. It's not OO mostly for the
reason that I've never done OO in Perl and didn't want to learn on
this one.
I have a couple of modules that are responsible for collecting user
data, a couple of modules that are responsible for the control logic,
a couple of modules that are responsible for calculating and preparing
the content, and an SQL module that handles the database stuff. I seem
to have a choice in the way the content is passed as the output as the
program: (1) either return the values to a main function that prints
the output, or (2) printing the output directly in the function that
calculates and prepares the output. IOW, I can do something like the
following:
FIRST OPTION:
my $content = calculate_content( \@vars);
print $content;
....
sub calculate_content
{
my $varref = shift;
my $output;
# do stuff like
$output .= output_from_other_functions();
return $output;
}
SECOND OPTION:
calculate_content( \@vars);
....
sub calculate_content
{
my $varref = shift;
my $output;
# do stuff like
$output .= output_from_other_functions();
print $output;
}
In out-putting the data, I can do it in the main function or do it in
helper functions. Which option is better? Why?
My preference is for (1) because I like to assign my variables in the
main function rather than hide the assignments in subroutines, but it
seems rather verbose and unnecessary here, so I'm tending toward (2),
but I'm not comfortable with it.
Thanks, CC.
concerned) that is growing rather large. It's not OO mostly for the
reason that I've never done OO in Perl and didn't want to learn on
this one.
I have a couple of modules that are responsible for collecting user
data, a couple of modules that are responsible for the control logic,
a couple of modules that are responsible for calculating and preparing
the content, and an SQL module that handles the database stuff. I seem
to have a choice in the way the content is passed as the output as the
program: (1) either return the values to a main function that prints
the output, or (2) printing the output directly in the function that
calculates and prepares the output. IOW, I can do something like the
following:
FIRST OPTION:
my $content = calculate_content( \@vars);
print $content;
....
sub calculate_content
{
my $varref = shift;
my $output;
# do stuff like
$output .= output_from_other_functions();
return $output;
}
SECOND OPTION:
calculate_content( \@vars);
....
sub calculate_content
{
my $varref = shift;
my $output;
# do stuff like
$output .= output_from_other_functions();
print $output;
}
In out-putting the data, I can do it in the main function or do it in
helper functions. Which option is better? Why?
My preference is for (1) because I like to assign my variables in the
main function rather than hide the assignments in subroutines, but it
seems rather verbose and unnecessary here, so I'm tending toward (2),
but I'm not comfortable with it.
Thanks, CC.