0

I have two arrays that have related data. I need to insert them into a html table. I am accessing these arrays from a different program by using modules which I found out by searching the forum.

package My::Module;
use strict;
use warnings;
use File::Slurp;
use Data::Dumper;
use Exporter;

our @ISA = 'Exporter';
our @EXPORT = qw(\@owners \@values);
our(@owners, @values);
$Data::Dumper::Indent = 1;

my @fileDatas = read_file("/x/home/venganesan/output.txt");

This is under a folder My and is named Module.pm. parts of the other file which will have the table are

use strict;
use warnings;
use CGI;
use My::Module;
my $q = new CGI;

print $q->header;
print $q->start_html(-title=>"Table testing", -style =>{'src'=> '/x/home/venganesan/style.css'});

print $q->h1("Modified WOWO diff");
print $q->table(        {-border=>1, cellpadding=>3},
        $q->Tr($q->th(['WOWODiff', 'Owner', 'Signoff'])),
        foreach $own(@owners){
        $q->Tr(
        $q->td([$own,'Two', 'Three'])},
        $q->td(['four', 'Five', 'Six']),

        ),

I am just trying to print one array to see how it works and then include the other. The output I am getting is both the arrays on command line without the html when I use Module.pm. If i remove it, I get html code. I am learning perl and new modules on the fly. I am open to criticism and better ways to implement the code.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
venkatvg
  • 13
  • 8

1 Answers1

0

It's 2013. No-one should be generating HTML using CGI.pm these days. By all means, use CGI.pm for generating headers and parsing CGI requests, but please consider using something like the Template Toolkit for your HTML.

I'm not clear what your question is. Are you saying that you get errors if you use My::Module (that's a terrible name for it, by the way)? In that case you should see what gets written to the web server's error log and address the problems given there.

Dave Cross
  • 68,119
  • 3
  • 51
  • 97
  • i just did a search for using html in perl and I found an example. I just tried to modify it according to my needs. The entire structure is from that example. I will use HTML::Template, thanks for the suggestion. My question : I have two arrays that I need to display as columns in a html table. The current scenario just prints the two arrays on the console when My::Module is removed, the html tags in the program get printed. – venkatvg Jul 29 '13 at 16:53
  • i tried using http://www.sitepoint.com/introducing-html-template/ . It was a lot easier to use html template. thank you for the help. – venkatvg Jul 29 '13 at 18:30
  • Huh? You found HTML::Template easier to use than HTML::Template? Did you look at the Template Toolkit - http://tt2.org/? – Dave Cross Jul 29 '13 at 19:20
  • Instead of using cgi, I used Html template. It did the job. I did not look at template toolkit, I thought you were referring to Html template. I saw the link, looks great. I will use it in my future projects. – venkatvg Jul 29 '13 at 20:42