Modularizing code (CBMG688P Best Practices laboratory, Stoltzfus)

In this lesson, we will take a few small steps to writing more modular code.

background

Much could be said on the topic of modularization and its advantages. Probably the most compelling thing to say is that the more experienced the programmer, and the more important and sustained the project, the smaller the modules get.

exercise

In the previous exercise, we worked on stamp_output.pl, and it ended up like this:
#!/usr/local/bin/perl -w
#
# stamp_output.pl - demo script for CBMG688P 
# 
use strict; 

my $version = '$Id$'; 
my $date = `date`; 
my $system = `uname -a`; 
 
print "# version = $version\n# date = $date\n# system = $system\n"; 

exit(0); 
Its pretty obvious how we should modularize this, right? By making a subroutine that creates the stamp.
#!/usr/local/bin/perl -w
#
# stamp_output.pl - demo script for CBMG688P 
# 
use strict; 

print MakeStamp; 

exit; 

####### subroutines ###### 
#
sub MakeStamp { 

   my $version = '$Id$'; 
   my $date = `date`; 
   my $system = `uname -a`; 
   
   my $stamp = sprintf("# version = $version\n# date = $date\n# system = $system\n" 
 
   return( $stamp ); 
}

exercise