• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Perl Newbie...need help (working on Windows)

Hi,
I am just learning perl and am stuck on my first simple script...

When i installed perl on c:/Perl it came with some example files....like this one:

------------------crash.cgi-------------------------------
#!/Perl/bin/perl


use CGI::Carp qw(fatalsToBrowser);

# This line invokes a fatal error message at compile time.
foo bar baz;
-------------------------------------------------

Which runs perfectly....


but when I make a slight change like this


------------------crash.cgi-------------------------------
#!/Perl/bin/perl

print "My first perl script";
-------------------------------------------------

It refuses to run, instead i get "Internal Server Error...blah blah blah"

What am i doing wrong?

Thanks!
0
fab_man_007
Asked:
fab_man_007
  • 5
  • 3
1 Solution
 
TintinCommented:
The

use CGI::Carp qw(fatalsToBrowser);

line directs any fatal errors to the browser.  Without it, you get a "500 internal server" error and you have to look for the error in the web server logs.
0
 
fab_man_007Author Commented:
update:

It works via the command line...and if i modify the program slightly like so:

use CGI ':standard';
print header;
print "Hello, World...\n";


I copied the above from another script....but no idea what it means....

help please....
0
 
TintinCommented:
Note that your script needs to also output a HTTP header, eg:

#!/Perl/bin/perl
print "Content-Type: text/plain\n\n";
print "My first perl script";

I'd always leave in the

use CGI::Carp qw(fatalsToBrowser);

while you are developing/debugging.

0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
fab_man_007Author Commented:
Hi Tintin,
I guess we were both writing at the same time....

I am learing perl from here: http://perldoc.perl.org/perlintro.html
and there it tells me just type

print "whatver you want here";

and it will show in the browser, but thats not happening....unless I do that "use CGI -:standard';


I come from a php side and i thought this would be simple or the same to learn.... :-(
0
 
fab_man_007Author Commented:
I think i have guessed it, unlike php....PERL needs to be told the content type before it will display....

Thanks for your help, sorry about the low points but I figured i will be needing quite a few questions here.. :-)
0
 
TintinCommented:
Note that the perlintro you were reading mentions nothing about output to a browser.  Remember Perl is a general purpose language whereas PHP is designed for web pages.  Therefore, you need to tell Perl if you are outputting HTTP headers or not.

The lines:

use CGI ':standard';
print header;

use the standard Perl CGI module and the 'print header', prints out a HTTP header, which depending on your version of Perl, will be the same as writing:

print "Content-Type: text/html; charset=ISO-8859-1\n\n";
0
 
fab_man_007Author Commented:
Cool, Thanks m8!
0
 
fab_man_007Author Commented:
I have come accross another problem and would appreciate your expert help there too if possible:
http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_21787395.html

Thanks in advance
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now