perl in CGI

G

Greg

I write a very simple CGI using perl,here is the html

<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

Following is the sunmoon.cgi
#!/usr/bin/perl -w
use CGI qw:)all);
my $hour=(localtime)[2];
my $image;

if($hour<6 or $hour >18){
$image="night.jpg";
}else{
$image="day.jpg";
}
print header;
print qq{<IMG SRC="$image" ALT="$image">\n};

The two image files are there, but it can not be shown on the webpage,
the webpage only shows:

Welcome to this web page. Currently, out my window I see:

What the problem? it seems the cgi was not executed. Thanks!
 
A

A. Sinan Unur

I write a very simple CGI using perl,here is the html

<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

I don't know anything about SSI, but that is SSI. Also, cig-bin is
misspelled. So the issue is related to the configuration of SSI for your
server, and not Perl.

Sinan
 
C

Chris Mattern

Greg said:
I write a very simple CGI using perl,here is the html

<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

Following is the sunmoon.cgi
#!/usr/bin/perl -w

use warnings; # is better than -w
use strict;
use CGI qw:)all);
my $hour=(localtime)[2];
my $image;

if($hour<6 or $hour >18){
$image="night.jpg";
}else{
$image="day.jpg";
}
print header;
print qq{<IMG SRC="$image" ALT="$image">\n};

The two image files are there, but it can not be shown on the webpage,
the webpage only shows:

Welcome to this web page. Currently, out my window I see:

What the problem? it seems the cgi was not executed. Thanks!

First: check the CGI script. What does it do when you run it from
the command line?

Second: check your image and HTML. Replace the CGI call with
a static <img> tag to one of the images. Do you see the image now?

Third: check your server logs; if your CGI script failed, your
error messages will be here. Alternatively you can
"use CGI:Carp qw(fatalsToBrowser);" and get your error messages
served up on the webpage.

Fourth: Don't capitalize your tags; it's bad form (and under strict
XHTML syntax, wrong, although it's not what's causing your problem).
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
G

Greg

I check all the things, it still doesn't work. It seems the cgi has
never been called. How can I check if the cgi being called?
Thanks!

Chris said:
Greg said:
I write a very simple CGI using perl,here is the html

<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

Following is the sunmoon.cgi
#!/usr/bin/perl -w

use warnings; # is better than -w
use strict;
use CGI qw:)all);
my $hour=(localtime)[2];
my $image;

if($hour<6 or $hour >18){
$image="night.jpg";
}else{
$image="day.jpg";
}
print header;
print qq{<IMG SRC="$image" ALT="$image">\n};

The two image files are there, but it can not be shown on the webpage,
the webpage only shows:

Welcome to this web page. Currently, out my window I see:

What the problem? it seems the cgi was not executed. Thanks!

First: check the CGI script. What does it do when you run it from
the command line?

Second: check your image and HTML. Replace the CGI call with
a static <img> tag to one of the images. Do you see the image now?

Third: check your server logs; if your CGI script failed, your
error messages will be here. Alternatively you can
"use CGI:Carp qw(fatalsToBrowser);" and get your error messages
served up on the webpage.

Fourth: Don't capitalize your tags; it's bad form (and under strict
XHTML syntax, wrong, although it's not what's causing your problem).
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
G

Greg

I check all the things, it still doesn't work. It seems the cgi has
never been called. How can I check if the cgi being called?
Thanks!

Chris said:
Greg said:
I write a very simple CGI using perl,here is the html

<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

Following is the sunmoon.cgi
#!/usr/bin/perl -w

use warnings; # is better than -w
use strict;
use CGI qw:)all);
my $hour=(localtime)[2];
my $image;

if($hour<6 or $hour >18){
$image="night.jpg";
}else{
$image="day.jpg";
}
print header;
print qq{<IMG SRC="$image" ALT="$image">\n};

The two image files are there, but it can not be shown on the webpage,
the webpage only shows:

Welcome to this web page. Currently, out my window I see:

What the problem? it seems the cgi was not executed. Thanks!

First: check the CGI script. What does it do when you run it from
the command line?

Second: check your image and HTML. Replace the CGI call with
a static <img> tag to one of the images. Do you see the image now?

Third: check your server logs; if your CGI script failed, your
error messages will be here. Alternatively you can
"use CGI:Carp qw(fatalsToBrowser);" and get your error messages
served up on the webpage.

Fourth: Don't capitalize your tags; it's bad form (and under strict
XHTML syntax, wrong, although it's not what's causing your problem).
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
T

Tintin

Greg said:
I write a very simple CGI using perl,here is the html

Actually, it's a SSI.
<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<BODY>
Welcome to this web page. Currently, out my window I see:
<!--#exec cgi="/cig-bin/sunmoon.cgi"-->
</BODY>
<HTML>

Following is the sunmoon.cgi
#!/usr/bin/perl -w
use CGI qw:)all);
my $hour=(localtime)[2];
my $image;

if($hour<6 or $hour >18){
$image="night.jpg";
}else{
$image="day.jpg";
}
print header;
print qq{<IMG SRC="$image" ALT="$image">\n};

The two image files are there,

Where do you think "there" is? I would be very surprised if you put the
images in your cig-bin (sic) directory. And even if they were, they
wouldn't be viewable unless you had a badly configured webserver.
but it can not be shown on the webpage,
the webpage only shows:

Welcome to this web page. Currently, out my window I see:

What the problem? it seems the cgi was not executed. Thanks!

Then you have a SSI/webserver configuration issue. None of which is related
to Perl.
 
A

axel

Greg said:
I check all the things, it still doesn't work. It seems the cgi has
never been called. How can I check if the cgi being called?

If the SSI is implemented and fails to call the script, the displayed
webpage will normally say that an error processing a directive has
occured.

Have a look at the source of the web page returned where it should
be apparent. If the SSI directive appears there intact as a comment,
it has not been run. Otherwise the results of the script may not
have been what you expected although I see nothing wrong with the
script.

However as others have noted, this is a webserver configuration
issue, not a Perl one.

Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top