Join 132,173 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,489 people online right now. Registration is fast and FREE... Join Now!
i tried that now I have and that doesnt work either. Im so frustrated. I dont see the error. I wish there was something that could test perl for errors!
#!/usr/bin/perl #c06ex4.cgi - creates a dynamic Web page print "Content-type: text/html\n\n";
use CGI qw(:standard); use strict;
#declare variables my ($dept, $size); my @dept_and_names = ("Accounting", "John Montgomery", "Customer Service", "Carol Jefferson", "Customer Service", "Jill Paulo", "Research and Development", "Jeffrey Johnson", "Accounting", "Sam Rantini", "Payroll", "Susan Choi", "Research and Development", "LaChonda Washington", "Customer Service", "Nancy Smith");
#assign values to variables $dept = param('Dept'); $size = @dept_and_names;
#create Web page print "<html>\n"; print "<head><title>Berelli Company</title></head>\n"; print "<body><h2>$dept Department Employees</h2><br>\n"; for (my $x=0; $x<$size; $x=$x+2) { if ($dept eq $dept_and_names[$x]) { print "$dept_and_names[$x+1]<br>\n"; } } print "</body>\n"; print "</html>\n";
I wish there was something that could test perl for errors!
You can check for syntax errors but not logic errors. There are no syntax errors in your code. Your code seems to work, the problem might be that the input (param('Dept')) is not an exact match when compared to the data in the array:
if ($dept eq $dept_and_names[$x]) {
the "eq" operator checks that each string matches exactly, including upper and lower case characters, spaces, and etc. If I enter a test value it appears to work:
CODE
#!/usr/bin/perl #c06ex4.cgi - creates a dynamic Web page print "Content-type: text/html\n\n";
use CGI qw(:standard); use strict;
#declare variables my ($dept, $size); my @dept_and_names = ("Accounting", "John Montgomery", "Customer Service", "Carol Jefferson", "Customer Service", "Jill Paulo", "Research and Development", "Jeffrey Johnson", "Accounting", "Sam Rantini", "Payroll", "Susan Choi", "Research and Development", "LaChonda Washington", "Customer Service", "Nancy Smith");
#assign values to variables $dept = 'LaChonda Washington'; #<-- TEST VALUE $size = @dept_and_names;
#create Web page print "<html>\n"; print "<head><title>Berelli Company</title></head>\n"; print "<body><h2>$dept Department Employees</h2><br>\n"; for (my $x=0; $x<$size; $x=$x+2) { if ($dept eq $dept_and_names[$x]) { print "$dept_and_names[$x+1]<br>\n"; } } print "</body>\n"; print "</html>\n";
output:
CODE
Content-type: text/html
<html> <head><title>Berelli Company</title></head> <body><h2>LaChonda Washington Department Employees</h2><br> </body> </html>
Thanks for trying..I found the error. in the html file it was looking for c06ex04.cgi instead of c06ex4.cgi. I named my cgi file c06ex4. I figured it out just by using firefox.
QUOTE(KevinADC @ 7 Aug, 2008 - 10:54 AM)
QUOTE
I wish there was something that could test perl for errors!
You can check for syntax errors but not logic errors. There are no syntax errors in your code. Your code seems to work, the problem might be that the input (param('Dept')) is not an exact match when compared to the data in the array:
if ($dept eq $dept_and_names[$x]) {
the "eq" operator checks that each string matches exactly, including upper and lower case characters, spaces, and etc. If I enter a test value it appears to work:
CODE
#!/usr/bin/perl #c06ex4.cgi - creates a dynamic Web page print "Content-type: text/html\n\n";
use CGI qw(:standard); use strict;
#declare variables my ($dept, $size); my @dept_and_names = ("Accounting", "John Montgomery", "Customer Service", "Carol Jefferson", "Customer Service", "Jill Paulo", "Research and Development", "Jeffrey Johnson", "Accounting", "Sam Rantini", "Payroll", "Susan Choi", "Research and Development", "LaChonda Washington", "Customer Service", "Nancy Smith");
#assign values to variables $dept = 'LaChonda Washington'; #<-- TEST VALUE $size = @dept_and_names;
#create Web page print "<html>\n"; print "<head><title>Berelli Company</title></head>\n"; print "<body><h2>$dept Department Employees</h2><br>\n"; for (my $x=0; $x<$size; $x=$x+2) { if ($dept eq $dept_and_names[$x]) { print "$dept_and_names[$x+1]<br>\n"; } } print "</body>\n"; print "</html>\n";
output:
CODE
Content-type: text/html
<html> <head><title>Berelli Company</title></head> <body><h2>LaChonda Washington Department Employees</h2><br> </body> </html>