Search code examples
perlprintinghtml-tablecgi

How do I output an HTML table into a file from Perl?


I have to read values from a file, store them in an array and then output the values into an HTML table in an HTML file. What is the best way to do this? Using write() and format to write to the file, using CGI and print to write to the file, or just printing tr's and td's?

I have three columns and four rows (12 values).


Solution

  • Just use format and write(), and a loop to control the input. Like this:

        while($i<10){
            $name = $values[$i];
            $description = $values[$i+1];
            $price = $values[$i+2];
            write;
            $i = $i+3;
        }
    
    
        format BODY =
        <tr><td>@*</td><td>@*</td><td>$@####.##</td></tr>
                $name,          $description,                         $price
        .