Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Including perl-generated html in a webpage

Posted on 2006-11-12
29
Medium Priority
?
271 Views
Last Modified: 2013-12-25
This is a rank newbie question ...

I'm trying to include a dynamically-created table as part of a webpage. The dynamic part is generated by a perl script. I try the following:

<html>
Other stuff ...
<a href="pub.cgi">pub.cgi</a>
</html>

When I click on the link, it opens pub.cgi as a text file rather than executing it. No doubt I'm doing something obviously wrong. But oddly enough, neither of the two perl books i have address this, and i couldn't find help online.

tia, Bill
0
Comment
Question by:BlearyEye
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 7
  • 7
  • +1
29 Comments
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17925937
BlearyEye,

The server isn't set up to recognize or execute the file.  You can try to rename the extension to .pl and see if that works better.  If not, is this your web server or hosted by another?

If hosted by another you will need to contact the provider and let them know that you need to run perl scripts in that directory.  You can let them know that you will use the cgi extension for the file name.

If it is yours and you want specifics on how to fix then what is the server OS?

Let me know if you have any questions or need more information.

b0lsc0tt
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17926513
What web server are you running?  
Is it configured to run CGI programs?

If it is enabled, in most instances, you can only run CGI programs from a specific directory, typically cgi-bin, so your link should probably be:

<a href="/cgi-bin/pub.cgi">pub.cgi</a>
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17928336
Are you simply trying to create a hyperlink to a cgi script or are you trying to include the output of the other script as a table in this html file?  If the latter, you'll need to use an ssi include http://www.ssi-developer.net/ssi/ssi-include.shtml or better yet, change to using a template approach.

Such as:
HTML::Template http://search.cpan.org/~samtregar/HTML-Template-2.8/Template.pm
or
The Template-Toolkit http://www.template-toolkit.org/
or
Mason http://www.masonhq.com/
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 1

Author Comment

by:BlearyEye
ID: 17929383
Thanks, all. I'm trying to include the html output in the webpage. I'm trying to get this running locally on my Win XP pc before I try it on another host. I have IIS installed. Do I need to configure it further to recognize a .pl extension.

I looked over the templates somewhat; in fact, I had previously come across the samtregar material. While I'm sure those approaches have benefits, it doesn't seem like it should be that hard.
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17931284
You can't include the output of an other cgi script via a link tag, you need to use SSI (the first link I gave) or an iframe http://www.w3schools.com/tags/tag_iframe.asp.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17931453
Let me know if I am misunderstanding the problem.  I don't think that is the case but FishMonger's comment has me a little confused.

XP doesn't support running Perl scripts without an additional install.  It doesn't just need to recognize the pl extension but it needs to have the "engine" to run the script.  There are some good installs for Windows that should make this pretty easy.  ActivePerl is one that I have heard lots about and used in the past.  There is some information on doing this at http://www.cgi101.com/book/connect/winxp.html.

Let me know if this helps or if you have any questions.

bol
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17931579
I was making the bad assuption that BlearyEye already has Perl installed and is running this through a webserver such as apache.
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17931689
So, I need to install the Apache web server? I thot I could do this with IIS. I'd rather not have more than one web server running since that's sure to bog things down and might confuse things.

When I try http://localhost in Firefox, i'm prompted for a username & password. Not sure what that should be, but seems to indicate that a web server is running

I tried the iframe, but with the same result: it wanted to download the code instead of run it.

btw, I'm using FrontPage for editing. Not sure if that makes a difference here ...

Am raising points since this seems to be not quite so trivial an issue as I had thot.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17931877
Did you look at ActivePerl?  In some ways what you install is another server but not in the way you are thinking.  ActivePerl will only handle perl scripts and will run under IIS.

An iframe, browser or editing software will not make a difference.  To verify this you can post your code to a server that does support perl and the page will work.

bol
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17931991
You don't need to install apache, but it is a much better web server than IIS.

>> When I try http://localhost in Firefox, i'm prompted for a username & password.
If IIS is running, it sounds like it may not be configured correctly.  I haven't used IIS for a long time, so I won't be of much help in that area.

>> I tried the iframe, but with the same result: it wanted to download the code instead of run it.
That contradicts what you said you wanted.  >> When I click on the link, it opens pub.cgi as a text file rather than executing it.

If you use the iframe, the cgi script must return a complete page, not just a table.

I believe the main issue that we have is that you're not being very clear on exactly what you want to achieve or clear on exactly what you've tried.

0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17934804
Let me try to be clear about what I want to do.

I have a web page. I want to be able to display on that page a formatted table that's built from some data in a text file. When I open the page, I'd like to see the page with the table displayed. I've written a perl script that creates the table. Now I'd like to integrate it with the existing web page. I hope that's clearer ...

I tried installing Apache server. During install it complained that it cannot connect to port 0.0.0.0:80. I poked around on Apache support; it might be that something else is listening to that port (IIS?) I ran netstat -abn from a dos box and found that inetinfo.exe is listening on that port. I tried killing inetinfo.exe in win task manager, but it came right back again. A google on inetinfo.exe shows that it is indeed part of IIS. So do I have to turn off IIS to get this working?

0
 
LVL 48

Expert Comment

by:Tintin
ID: 17934929
You can't have IIS and Apache listening on the same port and IP address, so you'll need to turn off IIS if you want Apache to start (unless you start Apache on a different port, say port 81)

Do you need the page to be dynamic?  There's always overhead in creating dynamic pages, so if you can get away with generating a static page, say every 15 mins.

0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17934941
Thanks for the clarification.  That is what I have thought.

Why did you not try ActivePerl?  You will need to uninstall IIS if you want to use Apache.  Apache will take the place of IIS.  ActivePerl will work with IIS.  If you will be developing in ASP then you should leave IIS installed, remove Apache, and install ActivePerl.  If you will only use Perl then Apache is good and you can uninstall IIS.

Let me know if you have any questions.

bol
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17934973
Bolscott.  

What makes you think BlearyEye doesn't have Perl installed?  In their last post, he/she said "I've written a perl script that creates the table".  If Perl wasn't installed, the table would be able to be created.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17935057
@Tintin -
> When I click on the link, it opens pub.cgi as a text file rather than
> executing it.
That was the main clue.  Since Perl isn't part of XP and IIS and BlearyEye hasn't done something to install it then it isn't installed.  I think the part you quoted actually refers to a script that has been made but is not running.  That is what the sentence after that quote means to me.

bol
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17935131
I don't interpret it that way at all.  Just because you click on a link for a Perl/CGI script and it displays the source is absolutely no indication of whether Perl is installed on the machine or not.  In 99% of cases, it is due to the CGI configuration of the web server not being set correctly.

0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17935261
Blearyeye is a he ;) too bad we don't have a neutral gender animate pronoun in English ...

To clarify: yes, I do have the script working. And, in fact, I had previously installed Active Perl. So Perl itself is working just fine.

So: I've now removed IIS and Apache works just fine. So, one problem solved. I thot it was a bad idea to have two web servers at the same time. I re-installed Active Perl, and it did so without quibbling. Now I'm back to trying to get my code to work right. Here's what I have at the moment:

<html>
Other stuff ...
<iframe src ="pub.pl"></iframe>
</html>

When the frame appears, it's filled with the code for pub.pl, so pub.pl is still not recognized as a script that's supposed to provide the html contents of the frame.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17935391
BlearyEye.

Please read my comments in the first post I made about scripts in /cgi-bin
Also, please respond to my comments about static/dynamic pages.
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17935496
My page is static in the sense that when it loads, it runs the perl script once to generate the html. After that the script is inactive.

On the Win PC, where is cgi-bin? I copied my files to C:\Program Files\Apache Software Foundation\Apache2.2\cgi-bin. Same result, showed the script contents instead of the results.

The home page of http://localhost/ is located at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs. I copied my files there, same result.

0
 
LVL 48

Expert Comment

by:Tintin
ID: 17935576
The point I was getting to with dynamic and static pages is that if you don't need the data to be generated every single time a user requests a page, then you are much better of with a static page that is regenerated at regular intervals.

Suppose your home page called a Perl script everytime it was hit, where the information the script generated only changed every 24 hours.  Suppose your site was very popular and you got a million hits per day.  The overheads in running the Perl script a million times rather than just once will be enormous.

Anyway, back to your specific question.  Putting your script in the cgi-bin is the first step, now you just need to enable CGI in Apache.

Edit your httpd.conf file (not exactly where that is on Windows) and search for "ScriptAlias" and ensure it is uncommented.
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17937646
I get the point about static vs. dynamic. I'll think about it. There are various versions of the data file that I want to present depending on the user's preference, so I'm not sure I want to pre-generate all of them.

Back to Apache ... the ScriptAlias entry was already uncommented. It is

    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"

This is one of the options I tried (see my last post): I put all the files into cgi-bin but when I opened the main page, got the same result (the text of the perl script in the frame, not the html it's supposed to generate).
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17938976
Please post the contents of the script and if it'snopt too big, post the complete html file that calling the script.
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17939361
=====================================================================
HTML file:
=====================================================================
<html>

<head>

   <title>Dependable Distributed and Networked Systems @ OSU </title>

<base target="_blank">

<meta name="Microsoft Theme" content="siefast 0011, default">
</head>

<body background="_themes/siefast/osu_logo_bg.gif" bgcolor="#FFFFFF" text="#000000" link="#999999" vlink="#990000" alink="#666666" ><!--mstheme--><font face="Times New Roman">



<! ================ template ================================>



<!--mstheme--></font><table border="1" width="100%" bordercolordark="#666666" bordercolorlight="#666666">

  <tr>

    <td width="100%" bgcolor="#38B0DE"><!--mstheme--><font face="Times New Roman">



<font size=+3 face="helvetica" color="#CDCDCD">

Publications</font><!--mstheme--></font></td>

  </tr>

</table><!--mstheme--><font face="Times New Roman"><!--mstheme--></font></body>

xxx
<iframe
src ="pub.pl">
</iframe>

<a href="pub.pl">pub.pl</a><p>

yyy
</p>
</html>

================================================================
perl script
================================================================

#!/perl/bin/perl

      open (publist, "pub-cgi.htm");
      @raw=<publist>;
      close (publist);

      chop(@raw);      #remove line ends
#      print @raw;

      $st=join("",@raw);
#      print "\n\n","##",$st,"##";


      $st =~ s/\t//g;      #remove tabs
#      print "\n\n","##",$st,"##";


      @newlist=();

      $end=1;while($end)
{      if($st =~ m/<tr[^>]*>
            <td>(.*?)<\/td>      #year
            <td>(.*?)<\/td>      #category
            <td>(.*?)<\/td>      #author
            <td>(.*?)<\/td>      #title
            <td>(.*?)<\/td>      #venue
            <td>(.*?)<\/td>      #volpg
            <td>(.*?)<\/td>      #pdfps
            <td>(.*?)<\/td>      #bibtex
            <td>(.*?)<\/td>      #tr
            <td>(.*?)<\/td>      #present
            <td>(.*?)<\/td>      #comment
            <\/tr>/x)
      {
            $year=$1; $category=$2; $author=$3; $title=$4;
            $venue=$5; $volpg=$6; $pdfps=$7; $bibtex=$8; $tr=$9;
            $present=$10; $comment=$11;
            push (@newlist,substr(
                       $year."        ",0,8)
                  ."|".$year
                  ."|".$category
                  ."|".$author
                  ."|".$title
                  ."|".$venue
                  ."|".$volpg
                  ."|".$pdfps
                  ."|".$bibtex
                  ."|".$tr
                  ."|".$present
                  ."|".$comment
                  ."|\n\n");$st = $';
      }
            else {$end=0}

}
      $x=shift(@newlist);      #remove title line
#      print "\n\n",@newlist;
      @newlist = sort {$b cmp $a} @newlist;
#      print "\n\n",@newlist;

      print '<table border="1" id="table1">';

      $lastkey="";
      foreach $pub (@newlist)
      {
            $pub =~ s/\&nbsp\;//g;      #eliminate forced spaces
            ($key,$year,$category,$author,$title,$venue,$volpg,$pdfps,$bibtex,$tr,$present,$comment)
                  =split /\|/, $pub;
            if ($lastkey ne $key)
            {
              $lastkey=$key;
              print "\n",'<tr><td colspan="11"><p align="center"><b>',$key,'</b></td></tr>',"\n";
            }
            if ($year)
            {
              print "\n<tr>";
              print "\n\t<td>",$year,"</td>";
              print "\n\t<td>",$author,". <i>",$title,".</i> ";
              print $venue;
              print ", ",$volpg if $volpg;
              print ", ",$year;
              print ".";
              print "<br><b>[",$pdfps,",",$bibtex,"]";
              print " TR version [",$tr,"]" if $tr;
              print " <i>",$comment if $comment;
              print "\n\t</td>";
              print "\n\t<td>", $category,"</td>";
              print "</tr>\n";
            }
      }

      print "</table>";
0
 
LVL 28

Expert Comment

by:FishMonger
ID: 17939525
You need to change the shebang line, it needs to point to where perl is located.

Unless you installed it in a different directory, it should be:
#!c:/perl/bin/perl.exe
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 17939745
@Tintin - I hope you didn't think I was giving you a hard time.  I read the question wrong and I'm glad that you got it right.  Good job!

@BlearEye - Looks like progress is being made and I don't have anything to add.  Thanks for the fun question incase I don't end up posting anything else.

bol
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17941016
bol, thanks for your interest and help.

OK, I changed the shebang. Sorry to say, same result. Very puzzling ...

I tried editing httpd.conf to add another ScriptAlias:
    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"
    ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/folder/"
Apparently there can be more than one. I stopped and restarted the apache server.

Since htdocs is the location for localhost, this creates a cgi-bin folder in that tree. So in Firefox I went to
   http://localhost/folder/
Once there, I clicked on publications.html (the main page). But, as I mentioned, the outcome is still the same.

thanks for your patience in sticking with this.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 500 total points
ID: 17941193
The first time you had:

<a href="pub.pl">pub.pl</a><p>

Did you try

<a href="/cgi-bin/pub.pl">pub.pl</a><p>

do you have multiple versions of pub.pl in the Apache directorys?  If so, this will make it confusing as to which one you are referencing.
0
 
LVL 28

Accepted Solution

by:
FishMonger earned 500 total points
ID: 17943670
We could tack a step back and verify that you can execute a simple "Hello World" cgi script.

Remove the ScriptAlias lines that you added to the conf file but leave the default ScriptAlias section then stop/start the apache service.  Then create the following hello.pl script and put it in your cgi directory.

#!c:/perl/bin/perl

print "content-type: text/html\n\n";
print "<h1>Hello World!</h1>";

Call it up in the browser like this:

http://localhost/cgi-bin/hello.pl

If you get the "Hell World!" page, then put that into your html file in the iframe call and/or the href link, and make sure you use the path syntax that Tintin showed.  Then report back with the results.  If you recieve an error at ant point, copy/past the exact error message in in the browser as well as from the error.log file which is in:
"C:/Program Files/Apache Software Foundation/Apache2.2/logs
0
 
LVL 1

Author Comment

by:BlearyEye
ID: 17947233
It works! Wow! Thank you all so much. I was able to get from "hello world" to my own script and it looks great. Thanks again.
0

Featured Post

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

721 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