#!/usr/local/bin/perl # energy.pl # Author: Alan Levine #> # Calculates estimated maximum velocity for # input height using simple energy laws # #< # require("CGI.pm"); # Load CGI.pm library to handle input and objects use CGI qw(:standard :cgi-lib); use CGI::Carp qw(fatalsToBrowser); # parse form variables to array &ReadParse; # print return html header print header; if (($in{'height'} =~ /\d/) and ( $in{'height'} > 0) ) { # set the gravity constant if ( $in{'units'} eq "meters") { $g = 9.8; } else { $g = 32.0; } $vel = sprintf( "%d", sqrt( 2 * $g * $in{'height'})); print <<"end_html";

Simple Calculations

Equation Kinetic and Potential Energies

For the input height of $in{'height'} $in{'units'}, the energy equation provides an estimated maximum velocity of

$vel $in{'units'} / sec
end_html } else { print <<"end_html";

Simple Calculations

Equation Kinetic and Potential Energies

Sorry, but the entered height $in{'height'} $in{'units'} is not valid. To complete the calculation, the height, must be a number greater than 0. Please click your browser back button to try again end_html } exit;