top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Is there a way to generate HTML reports in perl

0 votes

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.

posted Jul 6, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
If I understood correctly, you need to use a templating system like Template-Toolkit.

1 Answer

0 votes

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:

*  Simple text replacement.
*  A tag with an associated callback.
*  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.

answer Jul 6, 2013 by anonymous
Similar Questions
+1 vote

Is there a shorter way to write $a = ! $a, please?

Something analogous to ++ and -- operators like $a !! or !! $a would negate the variable $a and return its previous or new value respectively.

+1 vote

I have a Linux machine and windows machine, I need to run a GUI of Linux machine on the windows machine.
I don't want to use putty or any other software. I have to use any Perl modules to achieve this please help.

+2 votes

I have this simple script to automatically print HTML selection option.

#!/usr/bin/env perl
use strict;
for (reverse(1943 .. 1991)){
  print "$_n";}

I need to print all the years between 18 and 73 without hard coding the range in the for loop as in the above. I am considering the use of localtime to compute the current year as below $yr=(localtime), but I cant think of an easy way to achieved what I want to do.

+1 vote

I have tried to install module PDF::FromHTML from cpan but not able to get it.
Please let me know any other module to do the same. please help