Help with Perl

Discussion in 'Perl' started by Brett Baisley, Mar 2, 2004.

  1. Hello

    I'm new to Perl and taking it as part of my class. I am making a Perl
    program that does some calculations and depending on the result it gets, it
    either failed or successful. If it fails, it calls the fail sub called
    failPage().

    I am not sure how to get it to work, specifially, how to call a function.

    This is what I am testing with:

    #!/usr/bin/perl -w
    use CGI ":standard";
    failPage();

    then it should call the failPage sub, which simply prints "Fail" to the
    page. However, it doesn't work. It says a server error, so I'm doing
    something wrong.

    Any suggestions?

    Thanks
    Brett Baisley, Mar 2, 2004
    #1
    1. Advertising

  2. Brett Baisley wrote:
    > I'm new to Perl and taking it as part of my class. I am making a
    > Perl program that does some calculations and depending on the
    > result it gets, it either failed or successful. If it fails, it
    > calls the fail sub called failPage().
    >
    > I am not sure how to get it to work, specifially, how to call a
    > function.
    >
    > This is what I am testing with:
    >
    > #!/usr/bin/perl -w
    > use CGI ":standard";
    > failPage();
    >
    > then it should call the failPage sub, which simply prints "Fail" to
    > the page. However, it doesn't work. It says a server error, so I'm
    > doing something wrong.


    You are obviously trying to execute the program as a CGI script (i.e.
    from a browser), which is something that you are probably not supposed
    to do in a Perl class for beginners.

    Run the program from the command prompt.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Mar 2, 2004
    #2
    1. Advertising

  3. Brett Baisley

    Joe Smith Guest

    Brett Baisley wrote:

    > #!/usr/bin/perl -w
    > use CGI ":standard";
    > failPage();


    Immediately after "use CGI" add this line:
    use CGI::Carp 'fatalsToBrowser';

    Next time, post the significant parts of the program.

    The three lines you posted are obviously missing the part with
    sub failPage {
    print header(-type => 'text/plain'); print "Failed\n";
    }

    Better yet, design your program so that is can be run from the
    command line, either a Unix/Linux shell or from the "C:\>" prompt.
    -Joe
    Joe Smith, Mar 3, 2004
    #3
    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. dpackwood
    Replies:
    3
    Views:
    1,794
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    298
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    677
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    294
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    686
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page