Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to generate HTML reports?

371 views
Skip to first unread message

*Shaji Kalidasan*

unread,
Jul 6, 2013, 10:43:30 AM7/6/13
to Perl Beginners
Greetings,

As I understand, Perl has excellent report-generation capabilities. By using formats, we can actually visualize how our output will look because the definition of a format in Perl is very similar to what you see on the output. Is there any way we to convert these formats into HTML reports?

My goal is to create good looking HTML reports. Please suggest/advice.

Any help is highly appreciated.
 
best,
Shaji
-------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to God.
-------------------------------------------------------------------------------

Ron Weidner

unread,
Jul 6, 2013, 12:40:27 PM7/6/13
to *Shaji Kalidasan*, Beginner Perl

Shaji,

I've recently (6 months ago) created just such an application.  My approach was to create a simple template engine that supports 3 kinds of "tags".  The template engine will read a template file looking for these tags.  When a tag is found, the text for the tag is replaced by a some value (perhaps sourced from a database).  The text around the tags is simply echoed out to a file or stdout.

The three types of tags are:
  1. Simple text replacement.
  2. A tag with an associated callback.
  3. A Command tag.
As stated before the simple tag is simply a text replace for the tag with a new value.  Optionally, a callback can be implemented to perform some action as a result of encountering the tag such as a formatting the value or performing a calculation.  The command tag is a little special.  It has a beginning and an ending.  The text between is considered a "sub template" and a callback is associated with the command.  This is how I implement things like looping.

The main idea of this approach is to build the template file in HTML in the first place, embed tags in the HTML, and separate the process of obtaining the data from the actual rendering of the template.  The engine it self could also be called an "Event Based Parser" if that helps.

One other feature that I implemented in this template system was to make the whitespace around the tags optionally significant.  Not important for HTML reports but I can "visually" build plain text reports using a text editor when needed.

The solution weighs in at about 800 lines of Perl and is built with OOP design.  So, to answer your question, you may want to consider a template solution.  Whether you roll your own solution like I did or use an existing template solution, I would consider this approach both viable and effective.

HTH

--
Ronald Weidner
Software developer for hire.
http://www.techport80.com


From: *Shaji Kalidasan* <shaji...@yahoo.com>
To: Perl Beginners <begi...@perl.org>
Sent: Saturday, July 6, 2013 10:43 AM
Subject: Is there a way to generate HTML reports?

Octavian Rasnita

unread,
Jul 7, 2013, 1:49:31 AM7/7/13
to *Shaji Kalidasan*, Perl Beginners
Greetings,

As I understand, Perl has excellent report-generation capabilities. By using formats, we can actually visualize how our output will look because the definition of a format in Perl is very similar to what you see on the output. Is there any way we to convert these formats into HTML reports?

My goal is to create good looking HTML reports. Please suggest/advice.

Any help is highly appreciated.
 
best,
Shaji
 
 
If I understood correctly, you need to use a templating system like Template-Toolkit.
Octavian
 

John SJ Anderson

unread,
Jul 7, 2013, 1:58:15 PM7/7/13
to Perl Beginners
On Sat, Jul 6, 2013 at 7:43 AM, *Shaji Kalidasan* <shaji...@yahoo.com> wrote:

> My goal is to create good looking HTML reports. Please suggest/advice.

N'th-ing the suggestion that you look at a templating system. My
current go-to in this area is Text::Xslate
(https://metacpan.org/release/Text-Xslate), but there are a *bunch* of
them on CPAN. Find one you like the looks of and go for it.

Unless you're looking to have the experience of doing it, I would
strongly recommend against trying to roll your own templating system.

I would also steer you away from formats. Templating systems are a
better approach, particularly if you're planning on generating HTML.

chrs,
john.

lesleyb

unread,
Jul 8, 2013, 8:18:55 AM7/8/13
to begi...@perl.org
On Sat, Jul 06, 2013 at 10:43:30PM +0800, *Shaji Kalidasan* wrote:
> Greetings,
>
> As I understand, Perl has excellent report-generation capabilities. By using formats, we can actually visualize how our output will look because the definition of a format in Perl is very similar to what you see on the output. Is there any way we to convert these formats into HTML reports?
>
> My goal is to create good looking HTML reports. Please suggest/advice.
>
>
> Any help is highly appreciated.
Hi Shaji

I don't know of any module that interprets perl formats into HTML.

I suggest you look at one of the templating systems available under Perl.

I have used both HTML::Template and Template::Tookit.

HTML::Template is simpler and not necessarily restricted to HTML output,
despite its name. I have used it in job control for another language. I'm
pretty sure this module could be used to produce the formatted hardcopy you
require and the HTML you require presumably for the same data.

The last release for HTML::Template was 17th Jan 2013.
http://search.cpan.org/~wonko/HTML-Template-2.94/

Template::Toolkit has an initial learning curve. You have to learn the
templating language used in the templates. There's plenty of support for this
at template-toolkit.org and in the pod for the module. Again you can use
Template::Toolkit to create an equivalent hardcopy output.

The last release for Template::Toolkit (also known as TT2) was 7th Feb 2012.
http://search.cpan.org/dist/Template-Toolkit/

One I haven't yet tried is Text::Xslate which might well be worth looking at.
Again you may well be able to produce both HTML and hardcopy output using this
module.

The last release for Text::Xslate was 6th July 2013.
http://search.cpan.org/~gfuji/Text-Xslate-2.0008/

I also can't comment on HTML::TextToHTML or HTML::FromText but they may equally
be of interest to you, given the work you have already committed into the
formats you're using.

Use http://search.cpan.org to look at these modules and decide.

Good luck

Lesley

*Shaji Kalidasan*

unread,
Jul 8, 2013, 8:42:15 AM7/8/13
to begi...@perl.org, lesleyb, John SJ Anderson, Octavian Rasnita, Ron Weidner
Hi Lesley,

Thanks a bunch for letting me know about bunch of options. I am inclined to go with HTML::Template. Thanks once again.

I would also like to thank John SJ Anderson, Octavian Rasnita and Ron Weidner for their valuable inputs. Your inputs are timely and valuable. As I have a stringent deadline, I may not be able to evaluate other options (viz. HTML::TextToHTML, HTML::FromText) but definitely I will be happy to test it sometime in the future.
 
Sincerely,

Shaji
-------------------------------------------------------------------------------
Your talent is God's gift to you. What you do with it is your gift back to God.
-------------------------------------------------------------------------------

From: 'lesleyb' <les...@herlug.org.uk>
To: begi...@perl.org
Sent: Monday, 8 July 2013 5:48 PM
Subject: Re: Is there a way to generate HTML reports?
--
To unsubscribe, e-mail: beginners-...@perl.org
For additional commands, e-mail: beginne...@perl.org
http://learn.perl.org/




0 new messages