Help with Perl

B

Brett Baisley

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
 
G

Gunnar Hjalmarsson

Brett said:
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.
 
J

Joe Smith

Brett said:
#!/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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top