Hello world/Web server: Difference between revisions

Content added Content deleted
(Perl: simplify IO::Socket::INET call by using LocalAddr and remove Proto ("tcp" is default anyway))
(perl: now the plack/plackup examples with port 8080)
Line 685: Line 685:
"Goodbye, World! (hello, visitor No. $vn!)\xd\xa";
"Goodbye, World! (hello, visitor No. $vn!)\xd\xa";
}</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;
$runner->parse_options('--host' => 'localhost', '--port' => 8080);
$runner->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 <lang Shell>plackup --host localhost --port 8080 script.psgi</lang> to start the webserver.


=={{header|Perl 6}}==
=={{header|Perl 6}}==