Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Newbie question - calling perl from html (http://www.velocityreviews.com/forums/t883828-newbie-question-calling-perl-from-html.html)

Charles 11-24-2003 01:22 AM

Newbie question - calling perl from html
 
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

A. Sinan Unur 11-24-2003 02:06 AM

Re: Newbie question - calling perl from html
 
Charles <charles_dunhill@postmaster.co.uk> wrote in news:9bWfnsLu0Vw
$EwSa@blueyonder.co.uk:

> 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
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov

Leigh 11-24-2003 02:26 AM

Re: Newbie question - calling perl from html
 

"Charles" <charles_dunhill@postmaster.co.uk> wrote in message
news:9bWfnsLu0Vw$EwSa@blueyonder.co.uk...
> 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.



Bob Walton 11-24-2003 03:48 AM

Re: Newbie question - calling perl from html
 
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


Charles 11-24-2003 12:20 PM

Re: Newbie question - calling perl from html
 
In message <3FC17EA8.50406@rochester.rr.com>, Bob Walton
<invalid-email@rochester.rr.com> 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

Charles 11-24-2003 12:20 PM

Re: Newbie question - calling perl from html
 
In message <Xns943CD6ACEE6D7asu1cornelledu@132.236.56.8>, A. Sinan Unur
<asu1@c-o-r-n-e-l-l.edu> 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

Charles 11-24-2003 12:23 PM

Re: Newbie question - calling perl from html
 
In message <bprqcs$5j$1$8300dec7@news.demon.co.uk>, Leigh
<mail@dytron.demon.co.uk> 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

Dan Anderson 11-24-2003 03:37 PM

Re: Newbie question - calling perl from html
 
Charles <charles_dunhill@postmaster.co.uk> 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


All times are GMT. The time now is 11:16 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.