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

I just got curious some time ago, about what do I need to do to get my script (kind like this site) to be read straight in the other people's browser. I mean opening directly the .pl file in the URL path. Is the coding style different or is it something else ? Thank you all.

Replies are listed 'Best First'.
Re: Script in browser
by extremely (Priest) on Jan 17, 2001 at 11:09 UTC
    IF you already know basic CGI then it is generally just a matter of modifying your webserver configuration to allow perl scripts to be executed based on their extension in all directories or to specifically empower individual scripts.

    In apache this is as easy as:

    # .pl everywhere! AddHandler cgi-script .pl # # specific script <Location /index.pl> SetHandler cgi-script </Location>

    A third, rather more involved method is mod_perl. With other webservers, you are on your own...

    --
    $you = new YOU;
    honk() if $you->love(perl)

Re: Script in browser
by AgentM (Curate) on Jan 17, 2001 at 09:09 UTC
Re: Script in browser
by wardk (Deacon) on Jan 17, 2001 at 20:41 UTC

    this is really an http server config issue not really a coding issue.

    Note that the following information very much "depends" (and this isn't the forum for discussing http server issues so I will be brief as well as incomplete...read your http server docs).

    if the Perl file is in a directory defined as a cgi|shellcgi directory then it will be executed (this can "depend"). if you move this file to a non-cgi directory, then it also "depends" as to what will happen, often based on the extension. I find that on windows both NS and IE will ask you to either download the script or execute it using the windows mappings...i.e. if you have Perl installed on the local box, you may be prompted as to whether you desire the script to be run using Perl.exe. On unix, I find netscape will also want to "save as" the file locally.

    if you truly want your scripts to be viewed as source by everyone regardless of their platform then perhaps as easy solution is to change/remove the extension, to be sure you could copy the scripts to a non-cgi directory and rename them to script.html or just script. if on unix, be sure these are not marked executable. This is a kluge, but will work.

    as far as how the scripts get viewed as code here on perlmonks....the use of a custom tag pair, as documented Site How To