Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Newbie question - calling perl from html

Reply
Thread Tools

Newbie question - calling perl from html

 
 
Charles
Guest
Posts: n/a
 
      11-24-2003
Hi there.

This is probably the most basic of all questions, and I've looked at
various scripts which show how to do it (such as counters, time displays
etc) and online resources to get an answer, but my version still won't
work even though I'm using the same commands. I would be grateful if
someone could point me in the right direction before I tear my hair out!

All I want to do, and I'm doing this so I can learn how to use perl, is
display some text on a static web page.

I have index.html with the following

<html>
<body>
<p>This is some text</p>
<p><script src="../cgi-bin/hello.cgi"></script></p>
</body>
</html>

I have hello.cgi with the following (permissions are 755)

#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello. Thanks for dropping by\n";

But all the web page shows is:

This is some text

I've changed the src to the complete address but it still doesn't work.
Has anyone got any ideas on what I'm doing wrong?

Thanks in advance and I'm really sorry if this is so dumb, but I am
trying to learn as fast as I can.

Cheers!
--
Charles
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-24-2003
Charles <(E-Mail Removed)> wrote in news:9bWfnsLu0Vw
$(E-Mail Removed):

> Hi there.
>
> This is probably the most basic of all questions, and I've looked at
> various scripts which show how to do it (such as counters, time
> displays etc) and online resources to get an answer, but my version
> still won't work even though I'm using the same commands.


commands won't same my but version even work though

> I would be grateful if someone could point me in the right direction
> before I tear my hair out!


It seems like you Javascript, server side includes, and CGI are somehow
jumpled up together in your brain.

> I am trying to learn as fast as I can.


Slow down and learn each tool (concept, whatever) separately.

Sinan.

--
A. Sinan Unur
http://www.velocityreviews.com/forums/(E-Mail Removed)
Remove dashes for address
Spam bait: (E-Mail Removed)
 
Reply With Quote
 
 
 
 
Leigh
Guest
Posts: n/a
 
      11-24-2003

"Charles" <(E-Mail Removed)> wrote in message
news:9bWfnsLu0Vw$(E-Mail Removed)...
> Hi there.
>
> This is probably the most basic of all questions, and I've looked at
> various scripts which show how to do it (such as counters, time displays
> etc) and online resources to get an answer, but my version still won't
> work even though I'm using the same commands. I would be grateful if
> someone could point me in the right direction before I tear my hair out!
>
> All I want to do, and I'm doing this so I can learn how to use perl, is
> display some text on a static web page.
>
> I have index.html with the following
>
> <html>
> <body>
> <p>This is some text</p>
> <p><script src="../cgi-bin/hello.cgi"></script></p>
> </body>
> </html>
>
> I have hello.cgi with the following (permissions are 755)
>
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "Hello. Thanks for dropping by\n";
>
> But all the web page shows is:
>
> This is some text
>
> I've changed the src to the complete address but it still doesn't work.
> Has anyone got any ideas on what I'm doing wrong?
>
> Thanks in advance and I'm really sorry if this is so dumb, but I am
> trying to learn as fast as I can.
>
> Cheers!
> --
> Charles


Charles,

You can turn your text string into a link to call your Perl script thus:

<html>
<body>
<p><a href="../cgi-bin/hello.cgi">This is some text</a></p>
</body>
</html>

Note the use of the anchor tag <a>. You use the <script> tag to add code at
the client (browser), not the server. It should help you get started. Good
luck.

Cheers,

Leigh.


 
Reply With Quote
 
Bob Walton
Guest
Posts: n/a
 
      11-24-2003
Charles wrote:

....
> This is probably the most basic of all questions, and I've looked at
> various scripts which show how to do it (such as counters, time displays
> etc) and online resources to get an answer, but my version still won't
> work even though I'm using the same commands. I would be grateful if
> someone could point me in the right direction before I tear my hair out!
>
> All I want to do, and I'm doing this so I can learn how to use perl, is
> display some text on a static web page.
>
> I have index.html with the following
>
> <html>
> <body>
> <p>This is some text</p>
> <p><script src="../cgi-bin/hello.cgi"></script></p>



I think you've got Perl confused with JavaScript. JavaScript is a
feature of most every web browser these days; Perl is not. JavaScript
runs in the client's web browser. Your Perl script is a CGI script
which runs on your web server, not the client's machine. To access a
CGI script from your HTML, you will need to include one or more links in
your HTML (usually with either the <a href="../cgi-bin/hello.cgi"> link
text </a> or a form with a submit button. When the user clicks your
link or button, your CGI script will run on your server, and its output
will go back to the user's browser. One other thing you can do is have
the user input the URL of your CGI script directly, as in perhaps
something like http://www.whatever.com/cgi-bin/hello.cgi .

There is also something called PerlScript, but usually it also runs on
the web server and not the client's computer, and only on certain less
desirable OS's and web servers (I don't know much about it). It looks
like PerlScript can also run on the client side, but only if it is
installed there (in general, it won't be), and only on certain
undesirable OS's and browers.

Note that you should probably be very cautious about installing
PerlScript as part of your web browser -- it is probably much much less
secure that JavaScript, since Perl is a much more general language, with
access to lots more of your computer than JavaScript has. I would never
want a PerlScript script from an untrusted site to run on my computer.


> </body>
> </html>



....


Note that CGI setup issues are off-topic for this newsgroup (the issues
would be the same if the CGI program were written in C , sh, befunge or
whatever). If you have trouble with CGI, follow everything in:

perldoc -q 500

and then try comp.infosys.www.authoring.cgi . If you have trouble with
Perl, this is the place.

--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

 
Reply With Quote
 
Charles
Guest
Posts: n/a
 
      11-24-2003
In message <(E-Mail Removed)>, Bob Walton
<(E-Mail Removed)> writes

>I think you've got Perl confused with JavaScript. JavaScript is a
>feature of most every web browser these days; Perl is not. JavaScript
>runs in the client's web browser. Your Perl script is a CGI script
>which runs on your web server, not the client's machine. To access a
>CGI script from your HTML, you will need to include one or more links
>in your HTML (usually with either the <a href="../cgi-bin/hello.cgi">
>link text </a> or a form with a submit button. When the user clicks
>your link or button, your CGI script will run on your server, and its
>output will go back to the user's browser. One other thing you can do
>is have the user input the URL of your CGI script directly, as in
>perhaps something like http://www.whatever.com/cgi-bin/hello.cgi .


I don't think I explained myself clearly enough, which I thought I had
by explaining I'd looked at perl scripts for counters, time displays
etc. I wanted it to display both lines of text on the same page, not to
click on it as a separate page. The examples I looked at, of perl
scripts, were called via the script tag.

*snip detailed advice - thanks for the info!*

>Note that CGI setup issues are off-topic for this newsgroup (the issues
>would be the same if the CGI program were written in C , sh, befunge or
>whatever). If you have trouble with CGI, follow everything in:
>
> perldoc -q 500
>
>and then try comp.infosys.www.authoring.cgi . If you have trouble with
>Perl, this is the place.


Apologies - will look at the resource and direct my question to the
correct forum.

Cheers!
--
Charles
 
Reply With Quote
 
Charles
Guest
Posts: n/a
 
      11-24-2003
In message <Xns943CD6ACEE6D7asu1cornelledu@132.236.56.8>, A. Sinan Unur
<(E-Mail Removed)> writes

>commands won't same my but version even work though


I think I get the point you're using - that the same words in a
different order will be different even though they are the same. Is
that correct?

>It seems like you Javascript, server side includes, and CGI are somehow
>jumpled up together in your brain.


What I saw, which prompted me to try it, was a perl script to display
the time onto a static web page. They used the script tag to call the
perl script.

>Slow down and learn each tool (concept, whatever) separately.


I'm not a youngster - too short a life now to slow down.

Thanks for your help anyway. Another chap has advised this is the wrong
forum so I'll refer to other resources.

Cheers!
--
Charles
 
Reply With Quote
 
Charles
Guest
Posts: n/a
 
      11-24-2003
In message <bprqcs$5j$1$(E-Mail Removed)>, Leigh
<(E-Mail Removed)> writes

>You can turn your text string into a link to call your Perl script thus:
>
><html>
><body>
><p><a href="../cgi-bin/hello.cgi">This is some text</a></p>
></body>
></html>


I wanted it to display both lines at the same time - this is what I'd
seen with other perl scripts but couldn't get it to work.

>Note the use of the anchor tag <a>. You use the <script> tag to add code at
>the client (browser), not the server. It should help you get started. Good
>luck.


Thanks for the help. I'm going to take the advise of the other chaps
and read other resources before I try again.

Cheers!
--
Charles
 
Reply With Quote
 
Dan Anderson
Guest
Posts: n/a
 
      11-24-2003
Charles <(E-Mail Removed)> writes:

First off, from your responses to other posts, you seem to be
in a hurry to get this done. That's understandable, but it seems
you're very confused about how everything works. You talk of using
the right "keywords", whereas you're using several separate
technolgies (unsuccessfully) in your script:

1. HTML
2. CGI
3. Javascript

These are *distinct and seperate things*. So you need to
(ideally) attack the problem in those three different parts. Check
out safari.oreilly.com and get their 14 day free trial. Then you
might want to do some reading.

Your perl script outputs, for all intensive purposes, an HTML
document. You can only include it within a web page using an HTML or
javascript command to include an HTML web page. We know this because
you're outputting a text/html header.

Counters, however, use images. So all you need to do to
include a counter is by using an <img src=> tag. This doesn't help us
because, well, you're using a perl script which outputs a *web page*
and not an *image*.

You have four options for including *text* on a web page:

1. Don't use HTML or include all of the HTML in your perl
script. If you include all of the HTML from the web page
in your perl script you can just open the perl script like
it was a web page. If you don't use HTML you can figure
out some other way to communicate using Perl.

2. Use an iFrame element. <iframe="url"> puts the web page
from url into an inline frame with a scroll bar within the
web page. Unfortunately this is only properly supported
by IE (and possibly Opera -- not sure).

3. Use Javascript to read in the output of your script and
output it to the web page.

4. Create an image of the text you want to display, and
include it using an <img src=""> tag -- thus defeating the
need for embedding text within a web page.

-Dan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ calling perl script - Not able to get the stack arguments pushedrom XPUSH in perl script Yogi Perl Misc 1 09-13-2012 11:30 AM
Flash calling Php calling Perl Bill H Perl Misc 3 06-04-2009 03:32 PM
master perl calling slave perl Ela Perl Misc 9 05-04-2008 08:15 PM
what's wrong calling a Perl/CGI script in Perl/CGI script under Tomcat server? kath Perl Misc 4 04-09-2007 09:21 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM



Advertisments