Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Great dudes, Before you ask, this is not about cgi. I'd like to embed perl in plain ol' html (a 'la index.html). I've searched far & wide, and it looks like I should be able to:
<script language="perl"> print "Hello, World!!\n"; </script>
But alas, nothing comes of this in my browser (yes, I've cleared cache & checked the error_log). thanks, me ps, I am using apache, solaris 10, and firefox on the client side.

Replies are listed 'Best First'.
Re: Embedded perl in html
by Joost (Canon) on Apr 12, 2007 at 20:28 UTC
    You can't just put some perl code in an html page and expect it to run in your browser. You'd need a plugin for that - and I know no-one who has one installed.

    If you want to run the code on the server, there are plenty of options. If you want to run it just like that, I think PerlScript from activestate does work like that - but on IIS only as far as I know. If you want to allow for a slightly differnt syntax, you're probably better off using some templating module. There are gazillions of those on CPAN.

    update: just an example: http://www.masonhq.com/

Re: Embedded perl in html
by Trizor (Pilgrim) on Apr 12, 2007 at 20:10 UTC
    Thats the issue with the <script> tag. It depends on browser implementations. There isn't a browser I know of that has perl as an implemented script. So if you want client side perl you'll have to use some other method of distribution. Like CPAN.
      ok, here comes the newbie in me ;-) So this directive is stating that the processing is done on the client side? Is there any (legitimate) way to have embedded perl i nhtml execute on the server side?
        So this directive is stating that the processing is done on the client side?

        Since this directive is found in the HTML that the browser processes, it's for the client side. Otherwise you wouldn't see it, because it would have already been processed on the server side :-)

        For server side embedding perl in HTML, see e.g. HTML::Mason and eperl, for indirect embedding, see e.g. HTML::Template and Template::Manual::Intro.

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        With apache you can either use simple CGI scripts and the CGI module. If you're looking for a more advanced way to do things there is mod_perl, an countless modules built on it on CPAN. I'm not sure what you're trying to do with server side scripting so I can't point you to a more specific tutorial.
Re: Embedded perl in html
by ahmad (Hermit) on Apr 12, 2007 at 21:14 UTC

    There's something called Server Side includes (SSI)

    which can process html pages by the server (apache) then output it

    more info take a look at the apache tutorial

Re: Embedded perl in html
by Anonymous Monk on Apr 12, 2007 at 23:21 UTC
Re: Embedded perl in html
by jfluhmann (Scribe) on Apr 13, 2007 at 14:50 UTC
    You might also want to check out ActiveState's PerlScript.