CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Outputting text from a perl script to a html page.

 



mott3510
New User

Aug 12, 2009, 2:52 PM

Post #1 of 11 (912 views)
Outputting text from a perl script to a html page. Can't Post

I wrote a script in perl that outputs several lines of text. I can run the script in y terminal window by typing..../decodeMetars.pl KOUN KCAK. This will output the current conditions at each location in several lines of text. I have an already existing html page (forecast.html) and I would like to add what is output from that script directly to my html page. If at all possible I would like to be able to call the script from within my html page. Any help is greatly appreciated!


spider
User


Aug 12, 2009, 11:46 PM

Post #2 of 11 (905 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post

What you should do is to create a cgi-script to replace your forcast.html.
I don't think it is possible to run the script directly in you html-code.


FishMonger
Veteran / Moderator

Aug 13, 2009, 6:25 AM

Post #3 of 11 (897 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post

Based on your description of how you want to execute the script, I think you might want to look at using AJAX.
http://en.wikipedia.org/wiki/Ajax_(programming)

I've never worked with AJAX, so I can't help with its coding, but this tutorial may help.
http://www.w3schools.com/Ajax/Default.Asp

If you want a more Perlish solution, you could use HTML::Template and your html file would be the template.
http://search.cpan.org/~samtregar/HTML-Template-2.9/Template.pm


KevinR
Veteran


Aug 13, 2009, 9:18 AM

Post #4 of 11 (894 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post


In Reply To
I wrote a script in perl that outputs several lines of text. I can run the script in y terminal window by typing..../decodeMetars.pl KOUN KCAK. This will output the current conditions at each location in several lines of text. I have an already existing html page (forecast.html) and I would like to add what is output from that script directly to my html page. If at all possible I would like to be able to call the script from within my html page. Any help is greatly appreciated!


The simplest way might be to use an SSI tag in your html document (might have to change the extension to .shtm or .shtml) that calls the script and inserts the cgi script output. SSI tags are a way to have some dynamic content in an otherwise static html document. Most likely you will want to use the 'virtual' SSI tag. Something like:

<!--#include virtual="cgi-bin/decodeMetars.pl" -->

Google for SSI tutorials if you are totally unfamiliar with SSI.
-------------------------------------------------


mott3510
New User

Aug 13, 2009, 9:51 AM

Post #5 of 11 (892 views)
Re: [KevinR] Outputting text from a perl script to a html page. [In reply to] Can't Post

I figured that would be the easiest way and i tried:

<!--#include virtual="./decodeMetars.cgi KOUN"-->
<!--#exec cgi="./decodeMetars.cgi KOUN"-->

and keep getting the same error message:
[an error occurred while processing this directive]

I know this is a very common error and can be just about anything, but I have yet to figure out what is causing it.


KevinR
Veteran


Aug 13, 2009, 10:19 AM

Post #6 of 11 (891 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post


In Reply To
I figured that would be the easiest way and i tried:

<!--#include virtual="./decodeMetars.cgi KOUN"-->
<!--#exec cgi="./decodeMetars.cgi KOUN"-->

and keep getting the same error message:
[an error occurred while processing this directive]

I know this is a very common error and can be just about anything, but I have yet to figure out what is causing it.


I would use the actual folder name the script is in instead of ./

Does the perl script print a valid MIME header for the content it delivers before printing anything else?

Does the perl script have its permissions set correctly?

Can you run the perl script directly from its URL?
-------------------------------------------------


KevinR
Veteran


Aug 13, 2009, 10:22 AM

Post #7 of 11 (890 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post


In Reply To
I figured that would be the easiest way and i tried:

<!--#include virtual="./decodeMetars.cgi KOUN"-->
<!--#exec cgi="./decodeMetars.cgi KOUN"-->

and keep getting the same error message:
[an error occurred while processing this directive]

I know this is a very common error and can be just about anything, but I have yet to figure out what is causing it.


oops... this also looks wrong:

<!--#include virtual="./decodeMetars.cgi KOUN"-->

It is running as a CGI process so you need to send the data as query string data:

<!--#include virtual="./decodeMetars.cgi?name=KOUN"-->

and the perl script has to know it needs to extract KOUN out of the query string. Maybe using 'exec' you can send command line data to the perl script, but I'm not sure.
-------------------------------------------------


(This post was edited by KevinR on Aug 13, 2009, 10:22 AM)


mott3510
New User

Aug 13, 2009, 11:04 AM

Post #8 of 11 (884 views)
Re: [KevinR] Outputting text from a perl script to a html page. [In reply to] Can't Post

The perl script prints this heading:

print "Content-type: text/html\n\n" ;

I have checked the permissions and they are correct.

(I changed the perl code a bit so that it knows to pull KOUN from within the script, so now all I have to do is run it and it outputs what I need.)

I can run the script by putting the following in my terminal window:
./decodeMetars.pl

I also tried the entire path, like so:
<!--#include virtual="/webhost/hunter/http/decodeMetars.pl"-->

but I still get the same error.


KevinR
Veteran


Aug 13, 2009, 12:58 PM

Post #9 of 11 (882 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post

Is the script on a local http server or are you running it on a remote server (web hosting service)? If its a hosted account see if they have some SSI FAQs you can read or contact tech support. If you can't get it to work you may need to try and alternate method.
-------------------------------------------------


mott3510
New User

Aug 13, 2009, 2:36 PM

Post #10 of 11 (879 views)
Re: [KevinR] Outputting text from a perl script to a html page. [In reply to] Can't Post

It is a local http server. What other method would you suggest to try?


KevinR
Veteran


Aug 13, 2009, 5:53 PM

Post #11 of 11 (877 views)
Re: [mott3510] Outputting text from a perl script to a html page. [In reply to] Can't Post


In Reply To
It is a local http server. What other method would you suggest to try?


If its a local server then you should be able to get it to work. See your servers manual for SSI instructions or google around for them.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives