Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

simplest way to embed Perl in html

I've researched online and found several interesting Perl modules/frameworks, such as HTML:Mason, HTML::Embperl, or the MVC Catalyst framework, etc,which can let me embed Perl inside html, similarly like PHP code inside html.

However, my Perl project must be uploaded to uni server where only limited privilege and resources are provided.

For instance, Apache version 1.3.3 & Perl version 5.8.0 (lower than Catalyst's requirements)

I've used a script to check all installed Perl modules, only those names contain the word "html":

HTML::HeadParser    2.17
HTML::Entities  1.23
HTML::Filter    2.09
HTML::LinkExtor 1.31
HTML::Parser    3.26
HTML::PullParser    2.06
HTML::TokeParser    2.24
HTML::Tagset    3.03
HTML::Form  0.03

I am afraid none of them can let me embed Perl directly into html.

I know I can use simple print statement together with "heredoc" to print everything on html page inside Perl/CGI, but I reckon that violates the MVC design paradigm and is less flexible and more complicated to develop, mainly because now the business logic is messed up with html markups.

My current solution is to use jQuery to trigger AJAX requests to load html into specific tags from client-side. So in this case, Perl is only used to provide server-side data access, manipulated the related data and provide JSON formatted responses to the AJAX requests.

I wonder is there a better way to do that? I can hardly change the server status and I don't think the system admin would be that generous to install any other Perl modules.

Updated Info:

The main reason for embedding Perl into html is that I am very new to CGI programming, and since I am more familiar with PHP and jQuery, I'd like to know if there is a proper way to embed Perl directly into html, so I can finish off the client part very quickly and concentrate on the server-side.

Say, something like this:

<div id='user_status'>Your last visit was :[% getLastVisitDateTime($userId)%]</div>

Please bear with my little knowledge of Perl/CGI and many thanks to the help in advance.

Updated 2nd: Followed the Template Toolkit website instruction, I installed this module on my own MacBook Pro but unfortunately I cannot install it onto uni's server due to permission reason:

Warning: You do not have permissions to install into
 /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi 
at /usr/lib/perl5/5.8.0/ExtUtils/Install.pm line 84.
mkdir /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-
multi/auto/Template: Permission denied at /usr/lib/perl5/
5.8.0/ExtUtils/Install.pm line 137
make: *** [pure_site_install] Error 255

So unfortunately I am now seeking for other ways...

Okay, it seems HTML::Mason cannot be installed for the very same reason. Therefore I am afraid I must find a .pm only solution so that I don't have to install anything to the uni server's perl environment...

like image 950
Michael Mao Avatar asked Sep 04 '10 08:09

Michael Mao


People also ask

Does Perl work with HTML?

Use Perl Print statements to write an html document that has form fields and hyperlinks. It can say anything and just has to include one form field and one hyperlink to a file.


1 Answers

Don't embed Perl into HTML. Use a template system like Template Toolkit or HTML::Template. They can be directly copied to server (if you don't use XS stash for TT) or download ports for this OS and unpack.

like image 68
Alexandr Ciornii Avatar answered Sep 28 '22 05:09

Alexandr Ciornii