How to create a Perl module to be used in a CGI script

Discussion in 'Perl Misc' started by James, Aug 15, 2003.

  1. James

    James Guest

    Hi,

    I have the following:

    filename: Module1.pm

    package Module1;

    BEGIN {
    use Exporter();
    @ISA = qw(Exporter);
    @EXPORT = qw(&subroutine1);
    }

    sub subroutine1 {print "Hello!\n";}
    return 1;
    END { }
    ---------------------------------------------------
    Filename: Trial.cgi running in Tomcat 4.1.27

    #!c:\Perl\bin\perl.exe

    use CGI
    use Module1;

    subroutine1();
    ..
    ..
    ..
    ..


    When I run the script from my html page it asks for a file download. What am
    I doing wrong?

    Thanks, James
    James, Aug 15, 2003
    #1
    1. Advertising

  2. On 15 Aug 2003 10:52:03 -0700, James <> wrote:
    > Hi,
    >
    > I have the following:
    >
    > filename: Module1.pm
    >
    > package Module1;
    >
    > BEGIN {
    > use Exporter();
    > @ISA = qw(Exporter);
    > @EXPORT = qw(&subroutine1);
    > }
    >
    > sub subroutine1 {print "Hello!\n";}
    > return 1;
    > END { }
    > ---------------------------------------------------
    > Filename: Trial.cgi running in Tomcat 4.1.27
    >
    > #!c:\Perl\bin\perl.exe
    >
    > use CGI
    > use Module1;
    >
    > subroutine1();
    > .
    > .
    > .
    > .
    >
    >
    > When I run the script from my html page it asks for a file download. What am
    > I doing wrong?


    Besides forgetting to output a Content-type header followed by a blank
    line (unless your server somehow guesses that), I suspect you are using
    MSIE, which does not necessarily pay attention to MIME headers anyway.
    So it guesses based on its own criteria, which might include filename
    extension of the script. If that filename extension is associated with
    Perl.exe, it considers that insecure and asks if you want to download or
    execute it (not that you would have normally much luck executing CGI
    output).

    Note that MSIE considers "Content-type: text/plain" to be ambiguous (since
    it often a default for unknown filetypes), and would go through its
    guessing game for any text/plain content.

    --
    David Efflandt - All spam ignored http://www.de-srv.com/
    http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
    http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
    David Efflandt, Aug 16, 2003
    #2
    1. Advertising

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. praba kar

    Python-cgi or Perl-cgi script doubt

    praba kar, Jul 30, 2005, in forum: Python
    Replies:
    1
    Views:
    547
    Michael Sparks
    Jul 30, 2005
  2. fatted
    Replies:
    1
    Views:
    129
    Steve Grazzini
    Jul 25, 2003
  3. Replies:
    20
    Views:
    707
    Gunnar Hjalmarsson
    Jan 18, 2005
  4. shumsta
    Replies:
    1
    Views:
    255
    Fabian Pilkowski
    Jul 22, 2005
  5. kath
    Replies:
    4
    Views:
    582
    J. Gleixner
    Apr 9, 2007
Loading...

Share This Page