Help with Perl

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brett Baisley

    Help with Perl

    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


  • Gunnar Hjalmarsson

    #2
    Re: Help with Perl

    Brett Baisley wrote:[color=blue]
    > 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.[/color]

    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

    Comment

    • Joe Smith

      #3
      Re: Help with Perl

      Brett Baisley wrote:
      [color=blue]
      > #!/usr/bin/perl -w
      > use CGI ":standard" ;
      > failPage();[/color]

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

      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

      Comment

      Working...