Yesterday dragonchild wondered about the possibility to use Microsoft Internet Exploren as the user interface layer for client side Perl applications. I remembered vaguely that this was indeed possible and decided to check.

The answer is that you can actually perform client side Perl scripts in Internet Explorer using ActiveState's Perl. Part of the installation is PerlScript, an ActiveX component that ties in with Windows Scripting Host. Once installed, Perl scripts embedded in HTML with the <script> tag are executed in the browser just as JavaScript is.

The following is a simple example that shows the basics:

<html> <head> <title>Test</title> </head> <body> <script language="PerlScript"> $window->document->write("<h2>Table of factorials</h2>\n"); for ($i = 1, $fact = 1; $i <= 10; $i++, $fact *= $i) { $window->document->write("$i! = $fact<br>\n"); } </script> </body> </html>
As you can guess, this example was adapted from the JavaScript rinocerus book (p. 7 in the 3rd edition, O'Reilly). So provided you know the object model, you can do in PerlScript whatever you can in JavaScript. Now honestly I've only dabbled just a little bit in client side scripting, so I'm not going into useful things here. And yes, it's possible to load and use modules.

The reason I've always been slightly suspicious of PerlScript is shown in the following example:

<html> <head> <title>Test</title> </head> <body> <script language="PerlScript"> open(OUT, ">c:/Perl/perlscript.txt"); print OUT "Oh yes!\n"; close(OUT); </script> </body> </html>
Yes, this actually works when the page is loaded from a local disk. Since this is creepy, I checked whether this works when the HTML file is loaded from a webserver and fortunately it doesn't. It seems that PerlScript is subject to the same limitations as JavaScript. Whether this is a reassurance given Microsoft track record on security I'll leave to you to decide.

However, it is tempting to use PerlScript for client side scripting. If you can live with HTLM UI limitations and don't get nuts by keeping track of the state of your application it seems like a viable approach.

For the record, my setup: Windows XP Pro, IE 6, ActiveState Perl 5.8.3.809.

Just my 2 cents, -gjb-


In reply to Perl & IE by gjb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.