[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2006-03-23
8
Medium Priority
?
150 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!
0
Comment
Question by:fab_man_007
  • 5
  • 3
8 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 16276499
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
 

Author Comment

by:fab_man_007
ID: 16276503
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
 
LVL 48

Accepted Solution

by:
Tintin earned 200 total points
ID: 16276510
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
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 

Author Comment

by:fab_man_007
ID: 16276518
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
 

Author Comment

by:fab_man_007
ID: 16276527
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
 
LVL 48

Expert Comment

by:Tintin
ID: 16276755
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
 

Author Comment

by:fab_man_007
ID: 16280188
Cool, Thanks m8!
0
 

Author Comment

by:fab_man_007
ID: 16280366
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

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question