We help IT Professionals succeed at work.

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

fab_man_007
fab_man_007 asked
on
Medium Priority
162 Views
Last Modified: 2013-12-25
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!
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
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.

Author

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....
CERTIFIED EXPERT
Top Expert 2007
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.... :-(

Author

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.. :-)
CERTIFIED EXPERT
Top Expert 2007

Commented:
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";

Author

Commented:
Cool, Thanks m8!

Author

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
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.