Hi:
My setup is relatively simple so far. ActivePerl 5.8.3 on a Windows 98SE system. So
far PerlTidy is the only module I've specifically added to the system using the nmake
utility. I've lurking in the background for the past few weeks to get some ideas as to
others to add which might be useful.
I've been dabbling with the Open Perl Ide and I get a curious behaviour when I run one
of the programs I wrote for a course at school this year. When I click run within Open
Perl it pauses for input, then prints the text that should come first to display the
question, and proceeds to execute. If I just run it in a straight DOS window it prints
the question to screen and then pauses for input. Is there something I've missed in
the code or is this a quirk of the Open Perl IDE?? The code follows:
# paydata.pl: a very simple employee payroll calculation application.
# This program reads a tab-delimited text file prepared in Excel that
# is an employee time record. Calculated and output to the screen are
# employee name and number, gross pay, tax to be deducted, health
# insurance premium to be deducted, pension contribution to be
# deducted, and the resulting net pay.
#
# Each record is on a single line. Each field in the record is
# separated by a single tab character ("\t"). The database has four
# fields:
# - Employee name
# - Employee number
# - Hours worked
# - Pay rate per hour
# The name of the database file
$TheDB = "timesht.txt";
# Open the database file but quit if it doesn't exist
open( INDB, $TheDB ) or die "The database $TheDB could not be found.\n";
while (1) { # Loop forever
print "\nProcess the file (Y/N)? ";
chomp( $DoSearch = <STDIN> );
$DoSearch =~ tr/A-Z/a-z/;
# Check if they want to quit
if ( $DoSearch eq 'n' ) { last }
# Check if they did *not* say y or Y
unless ( $DoSearch eq 'y' ) {
print "\nYou must enter either Y or N.\n";
next; # Go out to the while loop
}
# Provide a line of separation and column titles
printf( "\n%-23s %-9s %-8s %-7s %-8s %-8s\n",
"Employee", "Gross", "Tax", "Health", "Pension", "Net" );
# Loop through the records in the file
while (<INDB>) {
# Input a line of the file, trim it, and break it
# into four variables
chomp( $TheRec = $_ );
( $Name, $ID, $Hours, $PayRate ) = split( /\t/, $TheRec );
# Calculate gross pay
if ( $Hours > 37.5 ) {
$GrossPay =
37.5 * $PayRate + ( ( $Hours - 37.5 ) * $PayRate * 1.5 );
}
else {
$GrossPay = $Hours * $PayRate;
}
# Calculate income tax payable
if ( $GrossPay >= 1000 ) {
$TaxPayable =
0.14 * 300 + 0.20 * 400 + 0.26 * ( $GrossPay - 999.99 );
}
elsif ( ( $GrossPay >= 600 ) and ( $GrossPay < 1000 ) ) {
$TaxPayable = 0.14 * 300 + 0.20 * ( $GrossPay - 599.99 );
}
elsif ( ( $GrossPay >= 300 ) and ( $GrossPay < 600 ) ) {
$TaxPayable = 0.14 * ( $GrossPay - 299.99 );
}
else {
$TaxPayable = 0;
}
# Calculate the health insurance premium as 1% of gross
# or $9.50, whichever is less
if ( $GrossPay * .01 > 9.50 ) {
$Health = 9.50;
}
else {
$Health = $GrossPay * .01;
}
# Calculate the pension plan contribution as 5% of gross
$Pension = $GrossPay * .05;
# The last is simple. Net is Gross minus the deductions
$NetPay = $GrossPay - $TaxPayable - $Health - $Pension;
# Print out the calculated pay information to the
# screen for each employee as you pass thru the
# loop
printf( "%-17s $ID: \$%8.2f \$%7.2f \$%6.2f \$%7.2f \$%8.2f\n",
$Name, $GrossPay, $TaxPayable, $Health, $Pension, $NetPay );
} # End of while(<INDB>)
# We only hit this line if we're done, so exit the loop
last;
} # End of while(1)
print "\nProgram finished.\n";
exit;
---
Brian Lunergan
Nepean, Ontario
Canada
---------------------------------
Post your free ad now! Yahoo! Canada Personals