# Display the Employee List in Perl



## jodiestjohn100 (Sep 22, 2008)

Hi 

I am working on a program and I need some help with the second part of this question. Displaying the employee List. Can somebody get back to me ASAP

Durham IT Services
----------------------------------------------------------------
A – Import data from a text file into the DBM file
B – Display the Employee List 
C – Modify the Employee details
D – Delete Employee details
E – Add an Employee
F – Find the number of employees by Position
X – Exit from the menu



!c:\perl\bin\perl -w
use strict;
my $option;
my($id,$name,$address,$city,$state,$phone,$email,$department,$position,$salary);
my $counter=0;
my $record;
my %Emp;
while ($counter cmp "A") {
system "cls";

print "Durham IT Services\n";
print "-------------------------------------\n";
print "A-Import data from a text file to an DMA file\n";
print "B-Display the Employees List\n";
print "C-Modify the Employee detail\n";
print "D-Delete Employee details\n";
print "E-Add an Employees\n";
print "F-Find the number of Employees by Position\n";
print "X-Exit from the Menu\n";

print "Choose an Option: ";
$option=<STDIN>;
chomp $option;


#Set up the command line option
my $filename = "employee.dat";
my $database = "employee.dbm";
#Open the input file
open (INPUT, "$filename") || die "Can not open the file $filename:";
#open the DBM database file
dbmopen(%Emp, $database, 0700) || die "Cannot open DBM database: $!";
#A while loop for the option on the main menu and the call to functions
print "Menu\n";
if ($option eq "A" or $option eq "a") {
import();
}
elsif ($option eq "B" or $option eq "b"){
print "B\n";
display();
print "Nice Job on B\n";
}
elsif ($option eq "C" or $option eq "c"){
print "C\n";
#modify();
}
elsif ($option eq "D" or $option eq "d"){
print "D\n";
#del();
}

elsif ($option eq "E" or $option eq "e"){
print "E\n";
#add();
}
elsif ($option eq "F" or $option eq "f"){
print "F\n";
#find();
}
elsif ($option eq "X" or $option eq "x") {
print "Exiting Program";
exit 0;
}
#Close the dmb database
dbmclose %Emp;
#Close the input file
close(INPUT);
}


sub import() {
while (<INPUT>)
{
chomp;
#Split the Line
($id,$name,$address,$city,$state,$phone,$email,$department,$position,$salary) = split(/\|/);
#Save the information into the DBM file
$Emp{$id} = "${name}|${address}|${city}|${state}|${phone}|${email}|${department}|${position}|${salary}"; 
}
}
import();

*sub display() {

while(($id) = each %Emp) 
{ 
# Split up the record. 
($id,$name,$address,$city,$state,$phone,$email,$department,$position,$salary)= split (/\|/); 
# print it 
print"$id\t $name\t $address\t $city\t $state\t $phone\t $email\t $department\t $position\t $salary\n";
} 
*


#Start printing out the dbm information
#while (($Emp, $record) = each %Emp)
#{
#Split the Record
# ($id,$name,$address,$city,$state,$phone,$email,$department,$position,$salary)= split (/\|/);
#print it
#print"$id\t $name\t $address\t $city\t $state\t $phone\t $email\t $department\t $position\t $salary\n"; 
#} 
} 
display();

sub modify() {
print "modify\n";
print "Choose an Option:\n";
$option=<STDIN>;
chomp $option;
}

sub del() {
print "Please enter your employee ID\n";
print "Choose an Option:\n";
$option=<STDIN>;
chomp $option;
}


----------



## McNinja (Jun 22, 2008)

sounds like homework to me 

we have a forum rule against this
http://www.techsupportforum.com/rules.php
EDUCATIONAL ASSISTANCE

While we are happy to promote the education of users, we feel it is inappropriate to circumvent the learning process by directly assisting with assignments and projects of an educational nature. Direct answers to school or college assignments are not allowed and will not be given. However, if a user is having trouble comprehending a certain topic, the members and staff at TSF will be happy to provide assistance with understanding the topic.


----------



## jodiestjohn100 (Sep 22, 2008)

I was posting this to not get the answer but to get some guidance about whats going on and why the code is wrong. I looked at his example and its what I have in it and it does not work. why?


----------



## dm01 (Oct 10, 2006)

You have lines commented which should not be. Find them and correct the error.


----------

