Newbie question - calling perl from html

Discussion in 'Perl Misc' started by Charles, Nov 24, 2003.

  1. Charles

    Charles Guest

    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, Nov 24, 2003
    #1
    1. Advertisements

  2. Charles <> wrote in news:9bWfnsLu0Vw
    $:

    > 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

    Remove dashes for address
    Spam bait: mailto:
     
    A. Sinan Unur, Nov 24, 2003
    #2
    1. Advertisements

  3. Charles

    Leigh Guest

    "Charles" <> wrote in message
    news:9bWfnsLu0Vw$...
    > 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.
     
    Leigh, Nov 24, 2003
    #3
  4. Charles

    Bob Walton Guest

    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
     
    Bob Walton, Nov 24, 2003
    #4
  5. Charles

    Charles Guest

    In message <>, Bob Walton
    <> 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, Nov 24, 2003
    #5
  6. Charles

    Charles Guest

    In message <Xns943CD6ACEE6D7asu1cornelledu@132.236.56.8>, A. Sinan Unur
    <> 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, Nov 24, 2003
    #6
  7. Charles

    Charles Guest

    In message <bprqcs$5j$1$>, Leigh
    <> 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
     
    Charles, Nov 24, 2003
    #7
  8. Charles

    Dan Anderson Guest

    Charles <> 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
     
    Dan Anderson, Nov 24, 2003
    #8
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bbxrider

    newbie perl - html question

    bbxrider, Oct 23, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    112
  2. pj
    Replies:
    3
    Views:
    336
  3. kath
    Replies:
    4
    Views:
    863
    J. Gleixner
    Apr 9, 2007
  4. Ela

    master perl calling slave perl

    Ela, May 4, 2008, in forum: Perl Misc
    Replies:
    9
    Views:
    215
    Uri Guttman
    May 4, 2008
  5. Bill H

    Flash calling Php calling Perl

    Bill H, Jun 4, 2009, in forum: Perl Misc
    Replies:
    3
    Views:
    281
    Mark Smith
    Jun 4, 2009
Loading...

Share This Page