I’m attempting to print fields in a form depending on the iteration using CGI. Is it possible to nest a for loop within a CGI print statement like so? I keep getting a syntax error on the for loop line…
print $survey->Tr(
$survey-td(
$survey->startform(name=>'survey', method => 'POST', action => 'survey.cgi'),
for ($i=0; $i < $size; $i++){
$survey->hidden(name=>"q$i", value => "currentQ[q$i]"),
$survey->submit(name=>'direction', value =>'Previous'),
$survey->endform(),
}
$survey->startform(name=>'survey', method=>'POST', action=>'survey.pl.cgi'),
$survey->submit(name=>'direction', value =>'Next'),
),
),
No. Instead you should push all the items on to an array (in advance of creating the parent element) and then pass the array as the argument.