Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks,

I want to set up my index.html file so that when the user typed in http://www.mysite.com/index.html it will load the default page and while the page is loading, it will run a perl script behind the scene to get a list of image files in a directory on the server and populate the drop down list in the index.html file. Is this possible? I see an option <BODY OnLoad="xxx">, is this where I would put my perl script name? Please advice.
Thanks.
  • Comment on Running a Perl script while loading Index.html

Replies are listed 'Best First'.
Re: Running a Perl script while loading Index.html
by GrandFather (Saint) on Nov 06, 2007 at 03:29 UTC

    Tell lies. Set your server up so that http://www.mysite.com/index.html actually resolves to a Perl script that renders the page and kicks off whatever other processing is required.

    You may find Web Programming in the Tutorials section helpful. If you need to kick off a long running process from your CGI script the answers to Managing a long running server side process using CGI may help.


    Perl is environmentally friendly - it saves trees
Re: Running a Perl script while loading Index.html
by Cody Pendant (Prior) on Nov 06, 2007 at 04:53 UTC
    Most servers, with the default setup, won't let you put a perl script into an HTML page with the extension ".html" -- you can use ".shtml" instead, or you can change the server settings so that ".html" is "server-parsed".

    Once you've got either of those sorted out, you can use a special include tag:

    <!--#exec cgi="/path/to/script"-->
    or possibly just
    <!--#include virtual="/path/to/script"-->
    but by the time you've gone to all that trouble, why not just create your whole page with Perl? If you don't have an "index.html" your server will probably look for "index.cgi" and display that instead.


    Nobody says perl looks like line-noise any more
    kids today don't know what line-noise IS ...
Re: Running a Perl script while loading Index.html
by scorpio17 (Canon) on Nov 06, 2007 at 14:40 UTC

    The onLoad="xxx" stuff is for running a javascript function - but your javascript function can invoke a server-side perl script via AJAX, which can them update the HTML of the page dynamically (in this case, populating the drop down list).

    So your "perl question" is actually a question involving HTML, javascript, perl/cgi, and AJAX - you have a lot of homework to do!