Bee H.
Bee H.

Reputation: 283

Trouble with CGI and table looping

I'm trying to create a table using cgi, populating it with content from an array, but I can't seem to find any answers online that solve my issue. I only have experience in languages like Java, and C++, so I'm not entirely sure what I'm doing when it comes to scripting, but here's what I have.

$c -> start_html(-title=>'Hello World'),

$c -> start_table({ -border => 1, -width => %50},
    while($i <= 4){
            $c -> tr({
                while($j <= 7 && $i + $j <=26){
                    $c -> td($alpha[$i + $j]),
                    $j++,
                }}),
            $i++,
    },
$c -> end_table,

$c -> end_html;

In my mind this seems like it would work, but it keeps returning a compilation error at while($i <=4), and says nothing else about the error. I could really use some help understanding this.

Upvotes: 0

Views: 84

Answers (1)

Chris Turner
Chris Turner

Reputation: 8142

To get the same effect as what you're trying to do, you could use the "map" function with a range and you'd end up with something like this.

my $i=0;
$c->table({-border=>1, -width => "%50"},
    map { $c->Tr(
        map { $c->td(($i<=26 ? $alpha[$i++] : ""),
            ); } (0..7)
        ) } (0..4)
    );

Upvotes: 1

Related Questions