homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

Perl within HTML
Can I use "<script language=Perl>"?

 3:01 pm on Mar 17, 2011 (gmt 0)

Is it possibe to use Perl in a way similar to Javascript? Can I do anything similar to this:

<script language="Perl">
Perl statements....



 8:52 pm on Mar 17, 2011 (gmt 0)

Yes, but not with your standard apache environment. You could use something like the Mason suite of modules that's allow you to go with
% while (my ($key,$value) = each(%ENV)) {
<b><% $key %></b>: <% $value %>
% }

Dear <% $name %>: We will come to your house at <% $address %> in the
fair city of <% $city %> to deliver your $<% $amount %> dollar prize!

The answer is <% ($y+8) % 2 %>.

You are <% $age < 18 ? 'not' : '' %> permitted to enter this site.

and more. Is that what you need?


 9:19 pm on Mar 17, 2011 (gmt 0)

I don't see anything in your code that tells the server to use the Mason suite. How is that done?


 10:13 pm on Mar 17, 2011 (gmt 0)

Mason - search.cpan.org:
http://search.cpan.org/~jswartz/Mason/lib/Mason.pm [search.cpan.org]


 11:06 pm on Mar 17, 2011 (gmt 0)

As far as I can see, Mason is used to generate the web page from within a Perl program. I know how to do that.

I want to use Perl statements from within an existing web page. I saw instructions on how to do it; tried it; got it to work; and then, rather stupidly, deleted the working page and the link to the internet location where I found the instructions.


 12:51 am on Mar 18, 2011 (gmt 0)

within an existing web page

are you looking for a server side method to process embedded perl or a client/user agent-type solution?


 1:20 am on Mar 18, 2011 (gmt 0)

I wish to do it server-side so that it works for everyone.


 7:40 am on Mar 18, 2011 (gmt 0)

Mason is perl code embedded in <%perl> tags within a (x)html document.
Mason uses a handler to serve the html with embedded perl document, similar to the mechanism used to serve cgi scripts.

if Mason isn't suitable to your requirements or doesn't match your style you might try HTML::Embperl:
http://search.cpan.org/~grichter/HTML-Embperl/Embperl.pod [search.cpan.org]


 3:09 pm on Mar 18, 2011 (gmt 0)

According to the documentation, Mason has to be installed on the server, and I don't have access to do that. Embperl is a Perl program which processes an input file to produce HTML output.

I'd really like to do this totally within HTML without installing anything on the server. I had it working but deleted it. Nuts!


 4:38 pm on Mar 18, 2011 (gmt 0)

There are two ways off the top of my head that will work for this, but it's not actually embedding perl "in the page."

The first and most obvious:

- make sure you can set .html extensions to be parsed by server side includes, OR change your html extensions to .shtml so they will be parsed by server side includes.

- Wherever you'd include "perl output," do this.

<!--#include virtual="/path/to/yourscript.pl" -->

or (some servers won't let you exec)
<!--#exec cmd="perl /path/to/yourscript.pl"-->

<!--#exec cgi="/path/to/yourscript.pl" -->

and you can even pass parameters; yourscript.pl would accept parameters via @ARGS

<!--#include virtual="/path/to/yourscript.pl blah=1 bleah=2" -->
or query string . . .
<!--#include virtual="/path/to/yourscript.pl?blah=1&bleah=2" -->

The advantage of the second is if you have a script that will be included OR called from the web it will work in either case without modification.

The second and probably more manageable method, though it would take a bit more programming, is to use the actual HTML files as "templates" and use "markers" where you would expect perl output. Looks like Mason is doing something "like" this, another is Template::Toolkit (which may already be installed in your environment.)

The advantage of this method is you don't need multiple requests for various scripts; you call a single script and it parses out the page as a template, replacing the markers with your data.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved