You can actually determine the number of columns dynamically from the
template, so it's not even necessary to hard-code that into your CGI.

Consider this snippet of template:

    <!-- TMPL_LOOP NAME="VAR_LIST" -->
    <tr>
      <!-- We have chosen three items per line -->
      <td><!-- TMPL_VAR NAME="VAR0" --></td>
      <td><!-- TMPL_VAR NAME="VAR1" --></td>
      <td><!-- TMPL_VAR NAME="VAR1" --></td>
    </tr>
    <!-- /TMPL_LOOP -->


You can grep the template for VARn within the named loop and count the
number of occurrences. You then build the data hash accordingly:

    # If width is zero then assume a single column of un-numbered names
    my $width = scalar grep { /^VAR\d+$/i } $template->query (loop =>
'VAR_LIST');

    my @envArray;
    do {
        my $envArray = {};
        my $counter = 0;
        foreach my $key (sort keys %ENV) {
            if (! $counter) {
                # Push existing hash onto list and reset for next iteration
                push (@envArray, $envArray) if scalar keys %$envArray;
                $envArray = {};
            }
            $envArray->{'VAR' . ($width ? $counter : '')} = $key;
            $envArray->{'VAL' . ($width ? $counter : '')} = $ENV{$key};
            $counter = ($counter + 1) % ($width || 1);
        }
        push (@envArray, $envArray) if scalar keys %$envArray;
    };

    $template->param (
        HOME => $ENV{HOME},
        PATH => $ENV{PATH},
        WIDTH => ($width || 1),
        ENV_ARRAY => \@envArray,
    );


Hope this helps,
Chris
--
Chris Davies, Manheim Online
Tel. 0113 393-2004  Fax. 0870 444-0482.  Mobile 07778 199069


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to