Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6593567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:41:53+00:00 2026-05-25T17:41:53+00:00

I figured out a way to create a quick web server in Perl: #!/usr/bin/env

  • 0

I figured out a way to create a quick web server in Perl:

#!/usr/bin/env perl -s -wl

use strict;

use HTTP::Daemon;
use HTTP::Headers;
use HTTP::Response;

sub help {
    print "$0 -port=<port-number>";
}

our $port;
our $addr = "localhost";

$port = 9000 unless defined $port;

my $server = HTTP::Daemon->new(
    LocalAddr => $addr,
    LocalPort => $port,
    Listen => 1,
    Reuse => 1,
);

die "$0: Could not setup server" unless $server;
print "$0: http://$addr:$port Accepting clients";

while (my $client = $server->accept()) {
    print "$0: Client received";

    $client->autoflush(1);

    my $request = $client->get_request;

    print "$0: Client's Request Received";
    print "$0: Request: " . $request->method;

    if ($request->method eq 'GET') {
        my $header = HTTP::Headers->new;
        $header->date( time );
        $header->server("$0");
        $header->content_type('text/html');

        my $content = "<!doctype html><html><head><title>Hello World</title></head><body><h1>Hello World!</h1></body></html>";
        my $response = HTTP::Response->new(200);
        $response->content($content);
        $response->header("Content-Type" => "text/html");

        $client->send_response($response);
    }

    print "$0: Closed";

    $client->close;
    undef($client);
}

But for some reason, every time I access localhost:9000 it displays part of the HTTP Header – date, server, content-length and content-type – and the content. It doesn’t render it as an HTML page. Is there something I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:41:54+00:00Added an answer on May 25, 2026 at 5:41 pm

    This is caused by the -l switch:

    #!/usr/bin/env perl -s -wl
                             ^
    

    It sets the output record separator to the value of the input record separator (a newline), which results in additional newlines being added to HTTP server output, and a broken HTTP response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am curious to know if anyone has figured out a way to create
I am trying to figure out the best way to create a view like
I am trying to figure out the best way to create a navigation menu
I'm trying to figure out the best way to create a class that can
I've figured out how to create a new UI element where I touch and
I'm using pygtk with PIL. I've already figured out a way to convert PIL
I have been trying to create a web service out some python scripts, and
I am new to Python and I haven't figured out a simple way of
Stuff I've already figured out I'm learning how to create a multi-tenant application in
I am new to powershell and have figured out how to use it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.