Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: INSERT file contents inside a table

by rnewsham (Curate)
on May 28, 2018 at 08:39 UTC ( #1215300=note: print w/replies, xml ) Need Help??

in reply to INSERT file contents inside a table

I always recommend not trying to print out html in the middle of perl code. It looks messy is a nightmare to maintain. Much better to break the html out into a template. If you want to keep it as a single script you can have the template in the cgi it still provides a level of separation. In my opinion something like this is much easier to read and maintain.

#!/usr/bin/perl use CGI ':standard'; use strict; use warnings; use CGI::Carp 'fatalsToBrowser'; # use only for testing use Template; my $cgi = new CGI; $cgi->header( -charset => 'utf-8' ); $ENV{"PATH"} = "/usr/sbin:/usr/bin:/sbin:/bin"; my %data; while(<DATA>) { chomp; my @columns = split; push @{$data{rows}}, \@columns } close FILE; my $tt = new Template; my $template = q( <!DOCTYPE html> <html> <head> <title>PM 1215287</title> </head> <body onload="parent.adjustMyFrameHeight();"> <div id='wrapper'> <table> <thead> <tr> <th>Time</th> <th>Category</th> <th>Sender</th> <th>Recipients</th> <th>Quarantined-ID</th> </tr> </thead> <tbody> [% FOR row=rows %] <tr> <td>[% row.0 %] [% row.1 %] [% row.2 %]</t +d> <td>[% row.3 %]</td> <td>[% row.4 %]</td> <td>[% row.5 %]</td> <td>[% row.6 %]</td> </tr> [% END %] </tbody> </table> </div> <style> body { background-color : #95B8DB; } #wrapper { min-height:500px; display:block; } table, tr, th, td { border : 1px solid grey; } </style> </body> </html> ); $tt->process( \$template, \%data ) or die $tt->error; __DATA__ May 3 15:58:17 SPAM spam-Lub +_LynRmcvj.gz May 3 15:58:24 SPAM spam-g +SCAdAuMpiD0.gz May 3 15:59:27 BANNED +banned-BpF8aM7FM48B May 3 16:00:29 SPAM spam- +6fFrrzUjgvug.gz May 3 16:01:48 INFECTED +virus-SZLvi-VO4IIv May 4 16:02:28 SPAM spam +-saYzvikxOfVL.gz May 4 16:02:45 SPAM spam-8 +K649OHNlRQ2.gz May 4 16:03:14 SPAM spam-3r +pUGn3IcDnG.gz

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1215300]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-12-01 14:49 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (10 votes). Check out past polls.