I agree with Ryan. I think it's often more useful to have a string
returned, giving me the option of what I want to do with it higher up.
If you have the makeCalendar() subroutine print, I would rename it to
something like outputCalendar() or something to that effect. I like to
make sure it's VERY clear when a subroutine is going to be interacting
with certain things, outside of the scope of the call (printing to
STDOUT, writing to the database, sending an email). Although those can
largely be stated in the subroutine header comments, I especially like
to identify sub's that are printing to STDOUT, since it has a direct
effect on the end user.
And of course, even make calendar could use templates if the actual
calendar output is complex, or might change. Unless it real short, I
try to pull content into a template. And if it's short, I like to put
it into a constant somewhere, making it as painless as possible to
change (because we all know it will someday). heh.
:)
-Alex
Ryan wrote:
> --At 4/15/02 4:25 PM -0500, PK Eidesis wrote:
>
>> sub makeCalendar {
>> $type = @_;
>> if($type eq "month") {
>> print "all the code for a monthly calendar";
>> elsif($type eq "week") {
>> print "all the code for a weekly calendar";
>> elsif($type eq "year") {
>> print "all the code for a yearly calendar";
>> }
>> }
>
>
> Personally, I'd change all those prints to returns - that way all of
> the following will work:
>
> print STDOUT makeCalendar("week");
> print $SOME_OTHER_HANDLE makeCalendar("week");
> my $four_weeks_in_a_row = undef;
> foreach (0..3) {
> $four_weeks_in_a_row .= makeCalendar("week");
> }
>
> Ryan
>
>