Link to home
Start Free TrialLog in
Avatar of fab_man_007
fab_man_007

asked on

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!
Avatar of Tintin
Tintin

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.
Avatar of fab_man_007

ASKER

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....
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.... :-(
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.. :-)
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";
Cool, Thanks m8!
I have come accross another problem and would appreciate your expert help there too if possible:
https://www.experts-exchange.com/questions/21787395/executing-pl-script-as-user-logins-via-htaccess.html

Thanks in advance