Don't you even dare think that Python is even close to the level of raw scripting convenience Perl has.
There are certain things I still use Perl for, but every time I do, I have to look up how to use one or more of its basic container types. Python's just so much easier to use.
But you're right, dedicated syntax for regular expressions makes a difference at times. I just don't reach for it nearly as often with Python, preferring string methods where possible or real parsers where necessary.
Granted, Python's regex support is still far superior to PHP's, which for some insane reason requires explicit delimiters inside a quoted string. (Yes, I know it lets you specify flags. That should have been a separate parameter.)
What about any of the Apache branches? It's probably simple enough to compile vanilla Apache for myself, but I'm feeling lazy and many of the branches just have plain installers.
That should be fine to start with. For the real server experience, you'll eventually want a Linux machine, where you can install Apache through the package manager.
Is it worth even learning PHP, or should I just start with Perl or Python? I've already used Python before but Django looks scary.
It's generally worthwhile to learn as many languages as you can, so you know which one's right for the job at hand. Fortunately, most of the concepts are shared, so each one tends to be easier than the last. For web in particular, Django can be complex, but not nearly as complex as creating a site by hand. Flask and Bottle are simpler alternatives, though they don't give you quite as much power out of the box. PHP is easier to start with, but all the little gotchas get annoying after a while, and starting without a framework leads to a fragile site. Perl is better for simple regex-based text processing, but Python's almost as good at that anyway, so you can live without it.
beside everyone is missing the main strength of php: hosting costs 12$/year. find a hosting with same feature and allowing for running a python/java server, I dare you.
Heroku does a decent job with their free tier, for low-traffic sites. But yes, it's much simpler to host multiple unrelated PHP sites together than Python webservers.
No, I gleaned that from looking at tutorials for getting a bare-bones web page up and running with Python. This is the hello world example from Python apparently:
No, that would be the hello world example for a particular framework. The equivalent of using CakePHP or some such; much messier to start up, but designed to make your life easier a few thousand lines of code down the road.
Granted, the pure Python code isn't that much simpler, though it's flexible enough to handle your routing example:
from SimpleHTTPServer import SimpleHTTPRequestHandler, test
class RequestHandler(SimpleHTTPRequestHandler):
def do_GET(self):
extensions = [
'.png',
'.jpg',
'.jpeg',
'.gif',
]
path = self.translate_path(self.path)
if any(path.endswith(ext) for ext in extensions):
SimpleHTTPRequestHandler.do_GET(self)
else:
self.send_html("<p>Welcome to Python</p>")
def send_html(self, text):
self.send_response(200)
self.send_header("Content-type", "text/html")
self.send_header("Content-Length", len(text))
self.end_headers()
self.wfile.write(text)
if __name__ == "__main__":
test(HandlerClass=RequestHandler)
And then you also need to also have the actual web page to render. How exactly is this easier than the equivalent version in PHP? It seems to require another whole layer of crap.
In both cases, the whole layer of crap is the web server itself, replacing Apache or php -S. Basically, PHP was designed to make the web part invisible, where Python is a more general-purpose language. Of course it's not quite as convenient as a more specialized language for certain tasks; the amazing part is that it's almost as good at everything, from text processing to web serving to data mining to desktop games.