When I see a repeating pattern I think 'can I loop this ?'

#!/usr/bin/perl use strict; use warnings; use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); # HTML my $q = new CGI; print $q->header; # start HTML printing in chunk print <<HTML; <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" +> <title>CommDesk Dashboard</title> <style type="text/css"> body { background-color: AliceBlue; } span.note1 {float:left} span.note2 {font-size:80%} table#t01, #t01 th, #t01 td { border: none; border-collapse: collapse; font-size:80%; } </style> </head> <body> <div style="float:left; width:50%"> <b>Call Volume Tab Configuration</b> <br/><span class="note2">Customize your personal view of the Call Volu +me Tab.</span> HTML
my @stat = ( ['trunk_usage' ,'% Trunk Usage'], ['pre_ivr' ,'Pre-IVR Call Volume'], ['trunk_group' ,'Trunk Group Utilization'], ['average_speed','Average Speed of Answer'], ['outage_call' ,'Outage Call Volume'], ['ivr_call' ,'IVR Call Volume'], ['non_outage' ,'Non-Outage Call Volume'], ['post_ivr' ,'Post-IVR Call Volume'],); my @row = (1,0,1,1,1,0,1,0); #while (my @row = $sth->fetchrow_array) { print qq!<table id="t01"><tr>!; for my $i (0..$#stat){ my $chk = ($row[$i] == 1) ? 'checked' : ''; print qq!<td> <input type="checkbox" name="$stat[$i][0]" value="1" $chk /> $stat[$i][1] </td>!; if (($i % 2) && ($i < $#stat)){ print q!</tr><tr>!; } } print q!</tr></table>!; #} print q!</div></body></html>!;
You need to put the database stuff back to replace the test values in @row, and probably the <form> tags but around the table not each input.
poj

In reply to Re^2: Can we use print <<HTML; twice in same file? by poj
in thread [Solved]: Can we use print <<HTML; twice in same file? by Perl300

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.