http://www.perlmonks.org?node_id=119908


in reply to Yet Another Stupid CGI Question

Greetings.

Not understanding while you want to interpolate the entire sub, I would offer more ways to do it.
(1)

# Trivial double loop - build, then print my $aref=[]; #reference to anonymous array. foreach $thing (@thingies) { push @{$aref},foo($thing); } print_table($aref); #... sub print_table { my $aryref=shift foreach my $thing (@{$aryref}) { #etc. } }

(2)
#bypass cgi's html facilities print '<table>'; foreach $thing (@thingies){ #foo returns an array of cell contents. print '<tr><td>',join('</td><td>', foo($thing)),'</td><tr>'; } print '</table>';
CGI's html convenience functions are - IMHO - just that, convenience (as opposed to the powerful parameter parsing, handling, etc. where CGI unreplaceably shines).
Sometimes rolling your own html can be just the thing.

Cheers,
alf