Hello world/Web server: Difference between revisions
Content added Content deleted
(Perl examples with Plack::Runner and plackup) |
(removed the last change --- it failed to listen to :8080 (it did a listen to :5000)) |
||
Line 680: | Line 680: | ||
close $client; |
close $client; |
||
}</lang> |
}</lang> |
||
Here's another solution using Plack (may be found on CPAN): |
|||
<lang Perl>use Plack::Runner; |
|||
my $app = sub { return [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ '<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>' ] ] }; |
|||
my $runner = Plack::Runner->new->run($app);</lang> |
|||
When using plackup, then this may be compressed to one line: |
|||
<lang perl>my $app = sub { return [ 200, [ 'Content-Type' => 'text/html; charset=UTF-8' ], [ '<html><head><title>Goodbye, world!</title></head><body>Goodbye, world!</body></html>' ] ] };</lang> |
|||
Use "plackup script.psgi" to start the webserver. |
|||
Using Perl's glue power, provide a suicide note with visitor counter via netcat: |
Using Perl's glue power, provide a suicide note with visitor counter via netcat: |
||
<lang Perl>while (++(our $vn)) { |
<lang Perl>while (++(our $vn)) { |