Writing Safe Code

An example program using my (II)

#!/usr/local/bin/perl

################################################################
# A program to convert a Michaelis-Menten plot to a
# Lineweaver-Burk plot
#
# Given the values of initial reaction velocity (V) measured as a
# function of initial substrate concentration (S), we subtract
# the background (\$bkg) from each value of V, and prepare lists of
# 1/S and 1/V.
################################################################

#declaration of variables (scope = entire program)

my @S = (2, 4, 6, 7, 10);          #S - Initial substrate concentration
my @V = (100, 130, 160, 170, 200); #V - Initial rate of product formation
my \$bkg = 90;                      #bkg - background
my @inverse_S;                     #1/V
my @inverse_V;                     #1/S

#subtract background from values of @V

foreach \$value (@V) {
\$value -= \$bkg;     # \$bkg is from before the loop
}

#calculate 1/S and 1/V

@inverse_S = calc_inverse (@S);
@inverse_V = calc_inverse (@V);

#print results

print "1/S @inverse_S\n";
print "1/V @inverse_V\n";

##################################################

sub calc_inverse {

my (@numbers) = @_;
my (@inv_numbers) = ();           # declaring and initializing @inv_numbers
# which is private to the function

foreach \$n (@numbers) {
my \$inverse = 1 / \$n;          # \$inverse is private to the loop
push (@inv_numbers, \$inverse); # @inv_numbers is from before the loop
}

return (@inv_numbers);
}