469,304 Members | 1,888 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,304 developers. It's quick & easy.

How to run .pl files in a browser? PERL

135 100+
I've tried to rename the perl file from .pl to HTML and this did not work. Currently I run my .pl files from the command prompt, how do I run them from a browser.

Please see the follow PERL code I'm trying to run in a browser:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. %pages = (
  4.     "fred" => "http://www.cgi101.com/~fred",
  5.     "Wilma" => "http://www.cgi101.com/~wilma",
  6. );
  7.  
  8. print "Content-type:text/html\n\n";
  9. print <<EndHdr;
  10.  
  11. <html><head><title>URL List</title></head>
  12. <body bgcolour="#ffffff">
  13.  
  14. <p>
  15. <h2>URL List</h2>
  16. <ul>
  17. EndHdr
  18.  
  19. foreach $key (keys %pages) {
  20.     print "<li><a href=\"$pages{$key}\">$key</a>\n";
  21. }
  22.  
  23. print <<EndFooter;
  24. </ul>
  25. <p>
  26. </body>
  27. </html>
  28. EndFooter
Sep 6 '07 #1
3 15159
KevinADC
4,059 Expert 2GB
You need to install and setup an http server on your local PC to run CGI scripts. apache is free and pretty easy to get setup. Ask in the apache forum how to go about doing it.

Browsers run HTML code, know what to do with javascript and CSS, but perl is just text to a browser. Could you imagine if browsers could run perl scripts that easily? Everyones computers would be hacked by the end of the day.
Sep 6 '07 #2
patelxxx
135 100+
Kevin,

I have setup Apache and is running, however when I run the code as a HTML file it gives me the following results, whereas I'm expecting the result to be same as the command prompt when I run it (perl variablehash.pl).

RESULTS in .html:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. %pages = (
  4.     "fred" => "http://www.cgi101.com/~fred",
  5.     "Wilma" => "http://www.cgi101.com/~wilma",
  6. );
  7.  
  8. print "Content-type:text/html\n\n";
  9.  
  10. print <<EndHdr;
  11.  
  12. <html><head><title>URL List</title></head>
  13. <body bgcolour="#ffffff">
  14.  
  15. <p>
  16. <h2>URL List</h2>
  17. <ul>
  18. EndHdr
  19.  
  20. foreach $key (keys %pages) {
  21.     print "$key\n";
  22. }
  23.  
  24. print <<EndFooter;
  25. </ul>
  26. <p>
  27. </body>
  28. </html>
  29. EndFooter
  30.  
Sep 7 '07 #3
KevinADC
4,059 Expert 2GB
You're confused. You don't embed perl in html. That is not the way to run perl base dCGI scripts. You write perl programs and, name them with .pl or .cgi extensions ( for now anyway), put them in the cgi-bin, and run them form there. So set up the cgi-bin to run executables and start putting your cgi scripts in the cgi-bin.
Sep 7 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by daniel kaplan | last post: by
reply views Thread by =?Utf-8?B?cGVsZWdrMQ==?= | last post: by
5 posts views Thread by Davo1977 | last post: by
3 posts views Thread by djia002 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.