Stamping output (CBMG688P Best Practices laboratory, Stoltzfus)

In this lesson, you will learn to use Perl tools to create a "stamp" so that your output is uniquely identifiable.

background

Stamping your output is a helpful habit to develop. Its like writing your name and the date on every assignment, the way that you used to do in grade school. The stamp allows you to trace the provenance of a result. If you don't have it, you migth not be able to remember how your produced a file. You can't be sure from the file name-- names can be changed. You can't be sure from the date on the file itself. When files are archived and unpacked, or when they are moved between servers, dates frequently get unintentionally overwritten (or "clobbered" in programmer language).

How are you going to tell when a file was produced? Which script (and which version of it) produced the output? What system was used to compute the result?

exercise

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

my $version = '$Id$'; 
my $date = ''; 
my $system = ''; 
 
print "# version = $version\n# date = $date\n# system = $system\n"; 

exit(0); 
When we changed version to $Id$, then committed this to CVS, we got a version stamp on our file. Here's the version string for this html file:

$Id: stamp_output_lesson.html,v 1.4 2010/12/20 15:54:25 arlin Exp $

That has a date on it, but its not now-- it's the date this file was checked in last. How do we get the present time, i.e., now?
unix_prompt$ date

And how can we get some information on our system? Like this:
unix_prompt$ uname -a

So, now we have everything we need to know except for one thing. How do we run a system command from within a Perl script? One way is with system( "command" ), but the one we want is `date`. The back-ticks are important. Without them, it won't work. Try it:
unix_prompt$ perl -e 'print date'
unix_prompt$ perl -e 'print "date"'
unix_prompt$ perl -e 'print `date`'

So, I will leave it to you to incorporate date and uname -a into the script.

Once that is done, let us check it in again using CVS.

What if you want to record all of the command-line options? Can someone figure that out?