tiny_monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello, Perl monks. I am currently studying how to generate a web page using PSGI/Plack. I read that it is not encouraged to use PSGI/Plack with any web development projects. Instead, a web framework that supports PSGI/Plack is recommended to those who would like to avail of the benefits of PSGI/Plack. However, I am still new to Perl. Down the road, I may use a framework if a job requires me to use one. But as of now, I don't think that using a framework will help me learn Perl and PSGI/Plack. That is why I am sticking to pure perl for now. Part of this learning process, I experienced having difficulty running a loop inside a PSGI application. The code goes like this:
#!/usr/bin/perl use strict; use warnings; use diagnostics; my $app = sub { my $html = get_html(); return [ 200, ['Content-Type' => 'text/html'], [$html] ]; }; sub get_html{ my @array; $array[0] = 'happy'; $array[1] = 'sad'; $array[2] = 'worrried'; return "<html> <head></head> <body> <select>"; foreach my $item (@array) {return "<option value='$item'>$item</option>";} return "</select> </body> </html>"; }
I gave the code a .psgi extension. I ran the code using the plackup command on the command line.The code produced a webpage on the browser that was ported to http://127.0.0.1:5000. But PSGI seemed to have ignored the foreach loop. In other words, the loop was not successfully invoked. I only got an empty dropdown menu. Unfortunately, I still do not know the solution to this problem. I'd very much appreciate if you could share your insight on this. Thanks.
|
|---|