Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Simple http server one-liner for some static files?

by will_ (Beadle)
on Mar 02, 2016 at 13:42 UTC ( #1156658=note: print w/replies, xml ) Need Help??

in reply to Simple http server one-liner for some static files?

Still looking for a one-liner that only uses core modules.
  • Comment on Re: Simple http server one-liner for some static files?

Replies are listed 'Best First'.
Re^2: Simple http server one-liner for some static files?
by Anonymous Monk on Mar 02, 2016 at 15:20 UTC

      Because I don't want to spend time and energy configuring CPAN, accounting for the company proxy, downloading a module, finding somewhere to put it, worrying about accidentally installing files in the wrong place, making the perl command refer to that location, etc. for every temporary webserver I want to make.

      While you may think all that is "easy", you can't honestly think it's as easy, fast and convenient as typing "python -m SimpleHTTPServer" or any other built-in one-liner?

        How about this approach:
        • Create a text file in a directory in your shell's PATH named
        • Paste the following code into the text file
          #!/usr/bin/env perl use HTTP::Daemon; my $port = $ARGV[0] || 8000; my $d = HTTP::Daemon->new(LocalPort => $port) or die $!; print " listening at: ", $d->url, "\n"; while (my $c = $d->accept) { while (my $r = $c->get_request) { $c->send_file_response(".".$r->url->path); } }
          If on a UNIX/Linux platform make sure to chmod +x
        • cd to the directory of your HTML content
        • execute to create a webserver on port 8000
          execute PORTNUMBER to create a webserver on port number of your choice

        The implementation (a perl script) is not a one liner, but the execution (calling the perl script) is...

        Perl does not have a simple HTTP server as part of its core modules. You will always have to download something from CPAN, which will always involve a bit more effort than your Python one-liner.

        So what is your point exactly? ... or are you just venting?

        If you want to use Perl to its fullest potential, you really should take the time to get to know how to use CPAN properly, and then yes, it will become relatively "easy".

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1156658]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2019-08-22 06:47 GMT
Find Nodes?
    Voting Booth?

    No recent polls found