This is a perl program intended for my chemistry class. Since I am just learning to write in Perl, which is my first language, can you tell me if you think that this is well written? If not, could you tell me what is wrong with it or what could be improved.
## Name:Titration
## Beginning of Program
#Input Variables
system "clear"; # Clear the Screen
print "Milliliters Solute: ";
chomp ($milliliters_solute=<>);
print "Milliliters Solvent: ";
chomp ($milliliters_solvent=<>);
print "Molarity of Solvent: ";
chomp ($molarity_solvent=<>);
print "Moles of Solute: ";
chomp ($moles_solute=<>);
print "Moles of Solvent: ";
chomp ($moles_solvent=<>);
system "clear"; # Clear the Screen
#Calculate Answer
$liters_solute=$milliliters_solute/1000;
$liters_solvent=$milliliters_solvent/1000;
$molarity=($liters_solute/$liters_solvent)*($molarity_solvent/1)*($moles_solvent/$moles_solute);
#Print Answer
system "clear"; # Clear the Screen
print "Molarity is $molarity \n";
## End of Program
EDIT: One year later. I've learned bash shell scripting since, and have written a lot of scripts in that, but haven't done as much work in Perl. Nonetheless, I've improved my little program to have functions, something I learned from bash, and made other small improvements.
#!/usr/bin/perl
# Name: Titration
# Author: Jonathan Bondhus
use strict; # Use strict perl parser
# Define the variables
my($milliliters_solute) = 0;
my($milliliters_solvent) = 0;
my($molarity_solvent) = 0;
my($moles_solute) = 0;
my($moles_solvent) = 0;
my($liters_solute) = 0;
my($liters_solvent) = 0;
my($molarity) = 0;
# Define the functions
sub my_define;
sub my_calculate;
sub my_print;
# Call the functions
&my_define;
&my_calculate;
&my_print;
sub my_define{ # Input Variables
system "clear"; # Clear the Screen
# Input milliliteres of solute
print "Milliliters Solute: ";
chomp ($milliliters_solute=<>);
# Input milliliters of solvent
print "Milliliters Solvent: ";
chomp ($milliliters_solvent=<>);
# Input molarity of solvent
print "Molarity of Solvent: ";
chomp ($molarity_solvent=<>);
# Input moles of solute
print "Moles of Solute: ";
chomp ($moles_solute=<>);
# Input moles of solvent
print "Moles of Solvent: ";
chomp ($moles_solvent=<>);
system "clear"; # Clear the Screen
}
sub my_calculate{ #Calculate Answer
$molarity=((($milliliters_solute/1000)/($milliliters_solvent))*($molarity_solvent)*($moles_solvent/$moles_solute));
}
sub my_print{#Print Answer
system "clear"; # Clear the Screen
print "Molarity is $molarity \n"; # Print the molarity
}
exit 0 ## End of Program