Embedding Perl Script into WordPress Blog Posts

In this example, I want to display the current time the page is viewed. A simple Perl script can do this:

print "Content-type: text/html \n\n";
$time = localtime();
print "<p>Hello World! It is $time</p>\n";

However, you cannot directly run Perl code in a blog post but you can embed the script into the post using iframe.

To embed a script directly into a post, use the iframe tag as follows:

<iframe name="iframe1" src=http://hostname/cgi-bin/helloworld.pl marginwidth="0" marginheight="0" scrolling="auto" width="100%" height="100"></iframe>

That’s it! This technique works for displaying any page you can display in your browser. It is just a frame (like a new browser window) displaying another page embedded in your site. You could theoretically even recursively embed your own page using iframes depending on your browser, but it stops at one iteration to prevent infinite recursion. Otherwise, simply change the src parameter to the URL you would like to embed on your page.

Recursively displaying your page using iframe
This is an example of how the browser handles the recurive use of the iframe tag.
If you'd like to share this, click below:

Leave a Reply

Your email address will not be published. Required fields are marked *