Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,513 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,760 people online right now. Registration is fast and FREE... Join Now!




the selection structure--error

 
Reply to this topicStart new topic

the selection structure--error, I am trying to write a script that prints the names of people from 4de

perluser
6 Aug, 2008 - 12:52 PM
Post #1

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 8

<!c06ex4.html>
<html>
<head><title>Berrelli Company</title><basefont size=5></head>
<body>
Click a department name<BR>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Accounting">Accounting</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Customer+Service">Customer Service</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Payroll">Payroll</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Research+and+Development">Research and Development</a><br>
</body>
</html>

The cgi code i have doesnt seem to working. It says the webpage cannot be found. Can anyone find the error. Im stuck.

#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');

#determine size of @dept_and_names array
$size = @dept_and_names;

#create Web page
print "<html>\n";
print "<head><title>Berelli Company</title></head>\n";
print "<body><h2>Department Employees</h2><br>\n";
for (my $x = 0; $x < $size; $x + 2) {
print "$size[$x]<br>\n";
}
print "</body>\n";
print "</html>\n";



User is offlineProfile CardPM
+Quote Post

KevinADC
RE: The Selection Structure--error
6 Aug, 2008 - 02:27 PM
Post #2

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
these urls look wrong:

?.netfirms.com

you can't have a '?' as part of the top level domain name. Should it be:

www.netfirms.com
User is offlineProfile CardPM
+Quote Post

perluser
RE: The Selection Structure--error
6 Aug, 2008 - 09:30 PM
Post #3

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 8

I just took out the name and replaced it with ?.
QUOTE(perluser @ 6 Aug, 2008 - 01:52 PM) *

<!c06ex4.html>
<html>
<head><title>Berrelli Company</title><basefont size=5></head>
<body>
Click a department name<BR>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Accounting">Accounting</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Customer+Service">Customer Service</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Payroll">Payroll</a><br>
<a href="http://?.netfirms.com/cgi-bin/c6/c06ex04.cgi?Dept=Research+and+Development">Research and Development</a><br>
</body>
</html>

The cgi code i have doesnt seem to working. It says the webpage cannot be found. Can anyone find the error. Im stuck.

#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');

#determine size of @dept_and_names array
$size = @dept_and_names;

#create Web page
print "<html>\n";
print "<head><title>Berelli Company</title></head>\n";
print "<body><h2>Department Employees</h2><br>\n";
for (my $x = 0; $x < $size; $x + 2) {
print "$size[$x]<br>\n";
}
print "</body>\n";
print "</html>\n";


User is offlineProfile CardPM
+Quote Post

KevinADC
RE: The Selection Structure--error
6 Aug, 2008 - 09:40 PM
Post #4

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
maybe this line:

print "$size[$x]<br>\n";

should be:

print "$dept_and_names[$x]<br>\n";

This post has been edited by KevinADC: 6 Aug, 2008 - 09:40 PM
User is offlineProfile CardPM
+Quote Post

perluser
RE: The Selection Structure--error
6 Aug, 2008 - 10:55 PM
Post #5

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 8

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";



QUOTE(KevinADC @ 6 Aug, 2008 - 10:40 PM) *

maybe this line:

print "$size[$x]<br>\n";

should be:

print "$dept_and_names[$x]<br>\n";


User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: The Selection Structure--error
7 Aug, 2008 - 01:23 AM
Post #6

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 799



Thanked: 51 times
Dream Kudos: 2175
My Contributions
The condition may be evaluating to false.
CODE

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";

User is offlineProfile CardPM
+Quote Post

KevinADC
RE: The Selection Structure--error
7 Aug, 2008 - 09:54 AM
Post #7

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
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>




User is offlineProfile CardPM
+Quote Post

perluser
RE: The Selection Structure--error
7 Aug, 2008 - 01:32 PM
Post #8

New D.I.C Head
*

Joined: 6 Aug, 2008
Posts: 8

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>



User is offlineProfile CardPM
+Quote Post

KevinADC
RE: The Selection Structure--error
7 Aug, 2008 - 02:04 PM
Post #9

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
by the way, learn how to use a hash instead of using an array when a hash is appropriate.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 09:02PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month