Ok I'm looking to find the array index of the entered employee number here is my code
-
#!/usr/bin/perl
-
# Uses module Text::CSV
-
# compiler directives
-
use strict;
-
use warnings;
-
use Text::CSV;
-
-
my $grossPay;
-
my $empNum;
-
my $numHours;
-
my (@empsNums, @empsName, @empsROP, @empsDept);
-
my $fileName = "emp.csv";
-
my @data;
-
my $status;
-
my @fields;
-
my $csv = Text::CSV->new();
-
my $counter = 0;
-
my $recordNum
-
-
&loadFile;
-
&getUserInput;
-
&search;
-
&displayCalc;
-
-
sub getUserInput
-
{
-
print "Please enter your employee number: ";
-
$empNum = <>;
-
chomp($empNum);
-
print "Please enter your number of hours worked: ";
-
$numHours = <>;
-
chomp($numHours);
-
}
-
-
sub loadFile
-
{
-
open (MYFILE, $fileName);
-
while (<MYFILE>)
-
{
-
chomp;
-
$data[$counter] = $_;
-
my $status = $csv->parse ($data[$counter]);
-
@fields = $csv->fields();
-
my($i) = 0;
-
foreach my $field (@fields)
-
{
-
if($i == 0)
-
{
-
$empsNums[$counter] = $field;
-
}
-
if($i == 1)
-
{
-
$empsName[$counter] = $field;
-
}
-
if($i == 2)
-
{
-
$empsDept[$counter] = $field;
-
}
-
if($i == 3)
-
{
-
$empsROP[$counter] = $field;
-
}
-
$i++;
-
}
-
$i = 0;
-
$counter++;
-
}
-
close (MYFILE);
-
}
-
-
sub displayCalc
-
{
-
print "\n";
-
print " Gross Pay Calculation";
-
print " \nEmployee Number: ".$empsName[$empNum];
-
print " \nEmployee Name: ".$empsName[$empNum];
-
print " \nEmployee Rate of Pay: ".$empsROP[$empNum];
-
print " \nEmployee Hours Worked: ".$numHours;
-
print " \nEmployee Gross Pay: ".$grossPay;
-
print " \n\n";
-
}
-
-
sub queryEmpNum
-
{
-
}
-
-
sub calcGPay
-
{
-
$grossPay = $numHours * $empsROP[$empNum];
-
}
-
The queryEmpNum should set the $recordNum
So like if I enter 105 it should look in the @empsNums array for the number 105 and then return the array index number of that value. thanks