There have been some good suggestions here, but no one has mentioned my particular favorite, which I use especially with html output.
I push everything onto an array, then just dump the array. This seems to work for me for a couple of reasons:
1. Format whitespace, easier readability.
2. Pass array
ref around to different subs, to build up output string in a modular format, without worrying about return values:
#!perl
main();
sub main
{
my @output;
push (@output, "Here is something to print out\n",
"Here is yet another line\n");
extra(\@output);
print @output;
}
sub extra
{
my $resRef = shift;
push (@$resRef, "Here is an extra line\n");
}
exit 0;