in reply to perl loops + html tables

Are you sure about your output? Shouldn't it be
col1 col2 col3 val1 val2 val3 val4 val5 val6

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: perl loops + html tables
by Anonymous Monk on Jan 10, 2005 at 13:14 UTC
    The output needs to be the other way round (like I said in the post).

    Cheers

      So col is more of a row?

      This code will do the trick:

      use strict; my @column_names = ('col1', 'col2','col3'); my @values = ('val1','val2','val3','val4','val5','val6', 'val7', 'val +8'); my $number_of_rows = @column_names; my $number_of_values = @values; my $row_number; print '<table>'; foreach my $row (@column_names) { print '<tr><td>',$row,'</td>'; for (my $value_number=$row_number; $value_number<$number_of_values +; $value_number+=$number_of_rows) { print '<td>',$values[$value_number],'</td>'; } $row_number++; print '</tr>'; } print '</table>';
      Note that the number of values does not have to be an integer multiple of the number of rows.

      CountZero

      "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law