I have a list of files/directories. I want to display this list in an HTML table having 'n' columns and an arbitrary number of rows. My script will either determine 'n' on it's own or have it passed in as a parameter, but my trouble lies with using the Table object in CGI.pm. I have mastered the part where I turn my list of files into an array (@fil_tbl) of anonymous arrays each of length 'n'. Here's the code I have been trying to make work with the Table object (actually this is the function-based method ... don't flog me):
print table ({width => 200}, (map { $my @t = @$_; Tr ({bgcolor => "#dddddd"}, foreach $fil (@t) { td ("$fil") }) } @fil_tbl ));
I'm getting a syntax error around the foreach statment. I am not sure if I need to enclose the foreach in (), in {}, make it a subroutine call instead, or perhaps I'm not on the right track at all.

In reply to Creating an HTML table with 'n' rows by husker

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.