in reply to How do I run a loop within a PSGI application
To follow up 1nickt's recommendation that you should use a templating system, consider:
use strict; use warnings; use HTML::Template; my $app = sub { my $htmlFile = genHTML_File(); my @options = map {{value => $_}} 'happy', 'sad', 'worrried'; my $tplt = HTML::Template->new(filename => $htmlFile); $tplt->param(options => \@options); return [200, ['Content-Type' => 'text/html'], [$tplt->output()]]; }; print $app->()[2][0]; sub genHTML_File { my $filename = 'delme.html'; open my $outHTML, '>', $filename or die "Can't create '$filename': + $!\n"; print $outHTML <<HTML; <html> <head></head> <body> <select><TMPL_LOOP name='options'> <option value='<TMPL_VAR name="value"/>'><TMPL_VAR name='value'/>< +/option></TMPL_LOOP> </select> </body> </html> HTML return $filename; }
Prints:
<html> <head></head> <body> <select> <option value='happy'>happy</option> <option value='sad'>sad</option> <option value='worrried'>worrried</option> </select> </body> </html>
In real code genHTML_File doesn't exist. Instead you put the HTML into an external file.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do I run a loop within a PSGI application
by tiny_monk (Sexton) on Aug 18, 2015 at 07:45 UTC | |
by GrandFather (Saint) on Aug 18, 2015 at 07:58 UTC | |
by 1nickt (Canon) on Aug 18, 2015 at 14:18 UTC | |
by GrandFather (Saint) on Aug 18, 2015 at 21:56 UTC |