Welcome to WebmasterWorld Guest from 54.227.5.198

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl within HTML

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

     

jalarie

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

10+ Year Member



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

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

janharders

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

WebmasterWorld Senior Member 5+ Year Member



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
  <ul>
% while (my ($key,$value) = each(%ENV)) {
<li>
<b><% $key %></b>: <% $value %>
</li>
% }
</ul>

or
 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?

jalarie

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

10+ Year Member



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

phranque

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

jalarie

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

10+ Year Member



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.

phranque

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



within an existing web page

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

jalarie

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

10+ Year Member



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

phranque

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

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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]

jalarie

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

10+ Year Member



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!

rocknbil

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

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



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"-->

or
<!--#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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month