in reply to How do I run a loop within a PSGI application
When you return from a sub, you exit the sub at that point, so the rest of it doesn't get executed.
You want this:
sub get_html { my @array = qw/ happy sad worried /; my $html = <<EOT; <html> <head></head> <body> <select> EOT foreach my $item (@array) { $html .= "<option value='$item'>$item</option>"; } $html .= <<EOT; </select> </body> </html> EOT return $html; }
Disclaimer: It's very bad practice to mix other languages with Perl. If you are printing HTML you should use a templating system, which keeps the HTML in separate files and just plugs in the values of your data. I suggest not writing your own.
|
|---|
| 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 06:23 UTC | |
|
Re^2: How do I run a loop within a PSGI application
by tiny_monk (Sexton) on Aug 18, 2015 at 06:06 UTC | |
|
Re^2: How do I run a loop within a PSGI application
by tiny_monk (Sexton) on Aug 18, 2015 at 06:09 UTC |