Question:

When I try to run a Perl script it asks me if I want to open or save file!

by  |  earlier

0 LIKES UnLike

Does this happen to you? AND DOES N E ONE NO HOW 2 FIX IT?

layenergylaw.com

 Tags:

   Report

3 ANSWERS


  1. Why bother code in perl if you can get it to execute right?


  2. As was stated, you don't necessarily have a problem with your Perl code at all.  You've got a problem with your webserver.

    When your webserver gets the request, it's supposed to take a look at the file requested (feedback.cgi) and either return the file to the requester, or run the program and give the output to the requester.  Which it does depends on the type of file that it is.  If it's a "*.html" file or a "*.jpg", etc, it just returns the file that was requested.  But if it's a "*.cgi" file, or a "*.pl" file, or a "*.php", etc, it needs to run the file as a program, and then return the output of that program to the requester.

    But your webserver isn't doing that.  It's returning the entire file without regard to the fact that it's a program, and NOT a flat file.  So for all intents and purposes, it thinks your ".cgi" file is just the same as an image file, a text file, an HTML file, or whatever.  It doesn't know that it should be running the program.

    You need to talk to the person who runs your webserver.  Which might be you!  If not, ignore below.

    If you're running Apache, you need to reconfigure the httpd.conf file (or whichever .conf file is relevant, depending) to specify that .cgi files should be executed, and not simply returned as flat content.  There are a few ways of doing this, and I have to admit I forget all the details of the "best" way.  I believe you want to add these lines (where appropriate, just search for them in your existing conf file, I think they're typically in there, but commented out, or modified slightly):

    AddHandler cgi-script .cgi

    AddType application/x-httpd-cgi .cgi

    That *should* (IIRC) set all ".cgi" files to run as executables as you'd expect them to.  The alternate way is to designate a particular directory as a CGI directory, meaning that ALL the files within it will be treated as though they were programs, regardless of their file extension:

    ScriptAlias /cgi-bin/ "/my/dir/cgi-bin/"

    If you're NOT running Apache, or you're not the web master, you'll need to do some more hunting around.  But there's your answer-- nothing to do with Perl, entirely your webserver.

    DaveE

  3. OK so when you click the submit button, rather than running your CGI program, the Perl code shows up in the browser.  You have to tell your webserver that your .cgi file is a program to execute.  Please read the "Idiot's Guide" (but don't take the title personally)

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.